Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimbaGithub authored and sfc-gh-ext-simba-lb committed Nov 2, 2022
1 parent 0612177 commit 9b8d4c9
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@ func postAuthCheckJWTToken(_ context.Context, _ *snowflakeRestful, _ *url.Values
}, nil
}

func postAuthCheckUsernamePasswordMfa(_ context.Context, _ *snowflakeRestful, _ *url.Values, _ map[string]string, jsonBody []byte, _ time.Duration) (*authResponse, error) {
var ar authRequest
if err := json.Unmarshal(jsonBody, &ar); err != nil {
return nil, err
}

return &authResponse{
Success: true,
Data: authResponseMain{
Token: "t",
MasterToken: "m",
MfaToken: "mockedMfaToken",
SessionInfo: authResponseSessionInfo{
DatabaseName: "dbn",
},
},
}, nil
}

func getDefaultSnowflakeConn() *snowflakeConn {
cfg := Config{
Account: "a",
Expand Down Expand Up @@ -469,3 +488,20 @@ func TestUnitAuthenticateJWT(t *testing.T) {
t.Fatalf("invalid token passed")
}
}

func TestUnitAuthenticateUsernamePasswordMfa(t *testing.T) {
var err error
sr := &snowflakeRestful{
FuncPostAuth: postAuthCheckUsernamePasswordMfa,
TokenAccessor: getSimpleTokenAccessor(),
}
sc := getDefaultSnowflakeConn()
sc.cfg.Authenticator = AuthTypeUsernamePasswordMFA
requestMfaToken := "true"
sc.cfg.Params[clientRequestMfaToken] = &requestMfaToken
sc.rest = sr
_, err = authenticate(context.TODO(), sc, []byte{}, []byte{})
if err != nil {
t.Fatalf("failed to run. err: %v", err)
}
}

0 comments on commit 9b8d4c9

Please sign in to comment.