本文整理汇总了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),