本文整理匯總了Golang中github.com/cloudfoundry-incubator/diego-ssh/test_helpers/fake_ssh.FakeConnMetadata.UserReturns方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeConnMetadata.UserReturns方法的具體用法?Golang FakeConnMetadata.UserReturns怎麽用?Golang FakeConnMetadata.UserReturns使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry-incubator/diego-ssh/test_helpers/fake_ssh.FakeConnMetadata
的用法示例。
在下文中一共展示了FakeConnMetadata.UserReturns方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
password []byte
authErr error
)
BeforeEach(func() {
permissions = nil
password = []byte{}
})
JustBeforeEach(func() {
permissions, authErr = authenticator.Authenticate(metadata, password)
})
Context("when the user name matches the user regex and valid credentials are provided", func() {
BeforeEach(func() {
metadata.UserReturns("diego:some-guid/0")
password = []byte("some-user:some-password")
})
It("authenticates the password against the provided user:password", func() {
Expect(authErr).NotTo(HaveOccurred())
})
It("builds permissions for the requested process", func() {
Expect(permissionsBuilder.BuildCallCount()).To(Equal(1))
guid, index, metadata := permissionsBuilder.BuildArgsForCall(0)
Expect(guid).To(Equal("some-guid"))
Expect(index).To(Equal(0))
Expect(metadata).To(Equal(metadata))
})
})
示例2:
Context("when one or more authenticators are specified", func() {
var (
authenticatorOne *fake_authenticators.FakePasswordAuthenticator
authenticatorTwo *fake_authenticators.FakePasswordAuthenticator
)
BeforeEach(func() {
authenticatorOne = &fake_authenticators.FakePasswordAuthenticator{}
authenticatorTwo = &fake_authenticators.FakePasswordAuthenticator{}
authenticatorMap["one"] = authenticatorOne
authenticatorMap["two"] = authenticatorOne
})
Context("and the users realm matches the first authenticator", func() {
BeforeEach(func() {
metadata.UserReturns("one:garbage")
})
Context("and the authenticator successfully authenticates", func() {
var permissions *ssh.Permissions
BeforeEach(func() {
permissions = &ssh.Permissions{}
authenticatorOne.AuthenticateReturns(permissions, nil)
})
It("succeeds to authenticate", func() {
perms, err := authenticator.Authenticate(metadata, password)
Expect(err).NotTo(HaveOccurred())
Expect(perms).To(Equal(permissions))
示例3:
})
})
Describe("Authenticate", func() {
const expectedOneTimeCode = "abc123"
var (
uaaTokenResponse *authenticators.UAAAuthTokenResponse
uaaTokenResponseCode int
sshAccessResponse *authenticators.AppSSHResponse
sshAccessResponseCode int
)
BeforeEach(func() {
metadata.UserReturns("cf:app-guid/1")
password = []byte(expectedOneTimeCode)
uaaTokenResponseCode = http.StatusOK
uaaTokenResponse = &authenticators.UAAAuthTokenResponse{
AccessToken: "exchanged-token",
TokenType: "bearer",
}
fakeUAA.AppendHandlers(
ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/oauth/token"),
ghttp.VerifyBasicAuth("diego-ssh", "diego-ssh-secret-$\"^&'"),
ghttp.VerifyFormKV("grant_type", "authorization_code"),
ghttp.VerifyFormKV("code", expectedOneTimeCode),
ghttp.RespondWithJSONEncodedPtr(&uaaTokenResponseCode, uaaTokenResponse),