コード例 #1
0
ファイル: get_ssh_code.go プロジェクト: krishicks/diego-ssh
func GetSSHCode(
	args []string,
	credFactory credential.CredentialFactory,
	output io.Writer,
) error {
	if len(args) != 1 || args[0] != "get-ssh-code" {
		return fmt.Errorf("%s\n%s", "Invalid usage", GetSSHCodeUsage)
	}

	code, err := credFactory.AuthorizationCode()
	if err != nil {
		return err
	}

	fmt.Fprintf(output, "%s\n", code)
	return nil
}
コード例 #2
0
			fakeInfoFactory.GetReturns(v2Info, nil)

			fakeUAA.RouteToHandler("GET", "/oauth/authorize", ghttp.CombineHandlers(
				ghttp.VerifyRequest("GET", "/oauth/authorize"),
				ghttp.VerifyFormKV("response_type", "code"),
				ghttp.VerifyFormKV("client_id", "ssh-oauth-client-id"),
				ghttp.VerifyFormKV("grant_type", "authorization_code"),
				ghttp.VerifyHeaderKV("authorization", "bearer client-bearer-token"),
				ghttp.RespondWith(http.StatusFound, "", http.Header{
					"Location": []string{"https://uaa.example.com/login?code=abc123"},
				}),
			))
		})

		It("forces the cli to refresh the access token used to acquire the access code", func() {
			_, err := credFactory.AuthorizationCode()
			Expect(err).NotTo(HaveOccurred())

			Expect(fakeCliConnection.CliCommandWithoutTerminalOutputCallCount()).To(Equal(1))
			Expect(fakeCliConnection.CliCommandWithoutTerminalOutputArgsForCall(0)).To(ConsistOf("oauth-token"))
			Expect(fakeCliConnection.AccessTokenCallCount()).To(Equal(1))
		})

		It("gets the access code from the token endpoint", func() {
			code, err := credFactory.AuthorizationCode()
			Expect(err).NotTo(HaveOccurred())

			Expect(fakeUAA.ReceivedRequests()).To(HaveLen(1))
			Expect(code).To(Equal("abc123"))
		})