This repository has been archived by the owner on Jun 27, 2024. It is now read-only.
forked from doitintl/gtoken
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Keith Mattix II
committed
Nov 12, 2021
1 parent
8d77900
commit b2ba37f
Showing
1 changed file
with
25 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,11 @@ import ( | |
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
const ( | ||
testEmail = "[email protected]" | ||
testToken = "jwt.token" | ||
) | ||
|
||
//nolint:funlen | ||
func Test_generateIDToken(t *testing.T) { | ||
type args struct { | ||
|
@@ -35,10 +40,10 @@ func Test_generateIDToken(t *testing.T) { | |
{ | ||
name: "one time token generation", | ||
args: args{ | ||
file: "jwt.token", | ||
file: testToken, | ||
}, | ||
fields: fields{ | ||
email: "[email protected]", | ||
email: testEmail, | ||
jwt: "whatever", | ||
}, | ||
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) { | ||
|
@@ -50,10 +55,10 @@ func Test_generateIDToken(t *testing.T) { | |
{ | ||
name: "one time token generation from email", | ||
args: args{ | ||
file: "jwt.token", | ||
file: testToken, | ||
}, | ||
fields: fields{ | ||
email: "[email protected]", | ||
email: testEmail, | ||
jwt: "whatever", | ||
}, | ||
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) { | ||
|
@@ -66,11 +71,11 @@ func Test_generateIDToken(t *testing.T) { | |
{ | ||
name: "refresh token generation", | ||
args: args{ | ||
file: "jwt.token", | ||
file: testToken, | ||
refresh: true, | ||
}, | ||
fields: fields{ | ||
email: "[email protected]", | ||
email: testEmail, | ||
jwt: "whatever", | ||
}, | ||
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) { | ||
|
@@ -93,10 +98,10 @@ func Test_generateIDToken(t *testing.T) { | |
{ | ||
name: "failed to generate token", | ||
args: args{ | ||
file: "jwt.token", | ||
file: testToken, | ||
}, | ||
fields: fields{ | ||
email: "[email protected]", | ||
email: testEmail, | ||
jwt: "whatever", | ||
}, | ||
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) { | ||
|
@@ -109,10 +114,10 @@ func Test_generateIDToken(t *testing.T) { | |
{ | ||
name: "failed to write token", | ||
args: args{ | ||
file: "jwt.token", | ||
file: testToken, | ||
}, | ||
fields: fields{ | ||
email: "[email protected]", | ||
email: testEmail, | ||
jwt: "whatever", | ||
}, | ||
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) { | ||
|
@@ -124,11 +129,11 @@ func Test_generateIDToken(t *testing.T) { | |
{ | ||
name: "failed to get duration from token", | ||
args: args{ | ||
file: "jwt.token", | ||
file: testToken, | ||
refresh: true, | ||
}, | ||
fields: fields{ | ||
email: "[email protected]", | ||
email: testEmail, | ||
jwt: "whatever", | ||
}, | ||
mockInit: func(ctx context.Context, sa *gcp.MockServiceAccountInfo, token *gcp.MockToken, args args, fields fields) { | ||
|
@@ -163,8 +168,8 @@ func Test_generateIDTokenCmd(t *testing.T) { | |
ctx := context.Background() | ||
mockSA := &gcp.MockServiceAccountInfo{} | ||
mockToken := &gcp.MockToken{} | ||
fileName := "jwt.token" | ||
email := "[email protected]" | ||
fileName := testToken | ||
email := testEmail | ||
mockSA.On("GetID", mock.AnythingOfType("*context.cancelCtx")).Return(email, nil) | ||
mockToken.On("Generate", mock.AnythingOfType("*context.cancelCtx"), email).Return("whatever", nil) | ||
mockToken.On("WriteToFile", "whatever", fileName).Return(nil) | ||
|
@@ -205,19 +210,17 @@ func Test_generateIDTokenCmdNoRefresh(t *testing.T) { | |
ctx := context.Background() | ||
mockSA := &gcp.MockServiceAccountInfo{} | ||
mockToken := &gcp.MockToken{} | ||
fileName := "jwt.token" | ||
email := "[email protected]" | ||
mockSA.On("GetID", mock.AnythingOfType("*context.cancelCtx")).Return(email, nil) | ||
mockToken.On("Generate", mock.AnythingOfType("*context.cancelCtx"), email).Return("whatever", nil) | ||
mockToken.On("WriteToFile", "whatever", fileName).Return(nil) | ||
mockSA.On("GetID", mock.AnythingOfType("*context.cancelCtx")).Return(testEmail, nil) | ||
mockToken.On("Generate", mock.AnythingOfType("*context.cancelCtx"), testEmail).Return("whatever", nil) | ||
mockToken.On("WriteToFile", "whatever", testToken).Return(nil) | ||
mockToken.On("GetDuration", "whatever").Return(31*time.Second, nil) | ||
mockToken.On("Generate", mock.AnythingOfType("*context.cancelCtx"), email).Return("whatever", nil) | ||
mockToken.On("WriteToFile", "whatever", fileName).Return(nil) | ||
mockToken.On("Generate", mock.AnythingOfType("*context.cancelCtx"), testEmail).Return("whatever", nil) | ||
mockToken.On("WriteToFile", "whatever", testToken).Return(nil) | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
go func() { | ||
err := startServerAndGenerator(ctx, mockSA, mockToken, fileName, false) | ||
err := startServerAndGenerator(ctx, mockSA, mockToken, testToken, false) | ||
assert.Nil(t, err, "generateIDTokenCmd should not return an error when context is canceled") | ||
wg.Done() | ||
}() | ||
|