MCPcopy
hub / github.com/spacecloud-io/space-cloud / TestIsTokenInternal

Function TestIsTokenInternal

gateway/modules/auth/auth_test.go:37–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

35}
36
37func TestIsTokenInternal(t *testing.T) {
38 var authCreateToken = []struct {
39 testName, token string
40 secretKeys []*config.Secret
41 IsErrExpected bool
42 }{
43 {testName: "Unsuccessful Test-Token has not been internally created", secretKeys: []*config.Secret{{IsPrimary: true, Secret: "mySecretkey"}}, IsErrExpected: true, token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbjEiOiJ0b2tlbjF2YWx1ZSIsInRva2VuMiI6InRva2VuMnZhbHVlIn0.h3jo37fYvnf55A63N-uCyLj9tueFwlGxEGCsf7gCjDc"},
44 {testName: "Unsuccessful Test-Signature is Invalid", IsErrExpected: true, secretKeys: []*config.Secret{{IsPrimary: true, Secret: "mySecretkey"}}, token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbjEiOiJ0b2tlbjF2YWx1ZSIsInRva2VuMiI6InRva2VuMnZhbHVlIn0.MKIZkrXy6nUMu5ejqiYKl7EOU1TxEoKTOww-eoQm6Lw"},
45 {testName: "Successful Test Case", IsErrExpected: false, secretKeys: []*config.Secret{{IsPrimary: true, Secret: "mySecretkey"}}, token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImludGVybmFsLXNjLXVzZXIifQ.k3OcidcCnshBOGtzpprfV5Fhl2xWb6sjzPZH3omDDpw"},
46 }
47
48 authModule := Init("chicago", "1", &crud.Module{}, nil, nil)
49 for _, test := range authCreateToken {
50 t.Run(test.testName, func(t *testing.T) {
51 _ = authModule.SetConfig(context.TODO(), "local", &config.ProjectConfig{Secrets: test.secretKeys}, nil, nil, nil, nil, config.EventingRules{})
52 err := authModule.IsTokenInternal(context.Background(), test.token)
53 if (err != nil) != test.IsErrExpected {
54 t.Error("Got This ", err, "Wanted Error-", test.IsErrExpected)
55 }
56 })
57 }
58}
59
60func TestParseToken(t *testing.T) {
61 var testCases = []struct {

Callers

nothing calls this directly

Calls 4

IsTokenInternalMethod · 0.80
InitFunction · 0.70
SetConfigMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected