forked from HuaweiTech/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_authenticator.go
61 lines (50 loc) · 1.52 KB
/
fake_authenticator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package api
import (
"github.com/cloudfoundry/cli/cf/configuration"
"github.com/cloudfoundry/cli/cf/errors"
)
type FakeAuthenticationRepository struct {
Config configuration.ReadWriter
AuthenticateArgs struct {
Credentials []map[string]string
}
GetLoginPromptsWasCalled bool
GetLoginPromptsReturns struct {
Error error
Prompts map[string]configuration.AuthPrompt
}
AuthError bool
AccessToken string
RefreshToken string
RefreshTokenCalled bool
}
func (auth *FakeAuthenticationRepository) Authenticate(credentials map[string]string) (apiErr error) {
auth.AuthenticateArgs.Credentials = append(auth.AuthenticateArgs.Credentials, copyMap(credentials))
if auth.AuthError {
apiErr = errors.New("Error authenticating.")
return
}
if auth.AccessToken == "" {
auth.AccessToken = "BEARER some_access_token"
}
auth.Config.SetAccessToken(auth.AccessToken)
auth.Config.SetRefreshToken(auth.RefreshToken)
return
}
func (auth *FakeAuthenticationRepository) RefreshAuthToken() (updatedToken string, apiErr error) {
auth.RefreshTokenCalled = true
return
}
func (auth *FakeAuthenticationRepository) GetLoginPromptsAndSaveUAAServerURL() (prompts map[string]configuration.AuthPrompt, apiErr error) {
auth.GetLoginPromptsWasCalled = true
prompts = auth.GetLoginPromptsReturns.Prompts
apiErr = auth.GetLoginPromptsReturns.Error
return
}
func copyMap(input map[string]string) map[string]string {
output := map[string]string{}
for key, val := range input {
output[key] = val
}
return output
}