forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_authenticator.go
44 lines (34 loc) · 962 Bytes
/
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
package api
import (
"cf/configuration"
"cf/net"
testconfig "testhelpers/configuration"
)
type FakeAuthenticationRepository struct {
ConfigRepo testconfig.FakeConfigRepository
Config *configuration.Configuration
Email string
Password string
AuthError bool
AccessToken string
RefreshToken string
}
func (auth *FakeAuthenticationRepository) Authenticate(email string, password string) (apiResponse net.ApiResponse) {
auth.Config, _ = auth.ConfigRepo.Get()
auth.Email = email
auth.Password = password
if auth.AuthError {
apiResponse = net.NewApiResponseWithMessage("Error authenticating.")
return
}
if auth.AccessToken == "" {
auth.AccessToken = "BEARER some_access_token"
}
auth.Config.AccessToken = auth.AccessToken
auth.Config.RefreshToken = auth.RefreshToken
auth.ConfigRepo.Save()
return
}
func (auth *FakeAuthenticationRepository) RefreshAuthToken() (updatedToken string, apiResponse net.ApiResponse) {
return
}