@@ -7,12 +7,11 @@ import (
77
88 "github.com/golang/mock/gomock"
99 "github.com/rs/zerolog"
10- "github.com/stretchr/testify/assert"
11-
1210 "github.com/snyk/go-application-framework/pkg/analytics"
1311 "github.com/snyk/go-application-framework/pkg/auth"
1412 "github.com/snyk/go-application-framework/pkg/configuration"
1513 "github.com/snyk/go-application-framework/pkg/mocks"
14+ "github.com/stretchr/testify/assert"
1615)
1716
1817func Test_auth_oauth (t * testing.T ) {
@@ -34,26 +33,26 @@ func Test_auth_oauth(t *testing.T) {
3433 assert .NoError (t , err )
3534
3635 t .Run ("happy" , func (t * testing.T ) {
37- config .Set (authTypeParameter , nil )
36+ config .Set (AuthTypeParameter , nil )
3837 authenticator .EXPECT ().Authenticate ().Times (2 ).Return (nil )
3938 mockInvocationContext := mocks .NewMockInvocationContext (mockCtl )
4039 mockInvocationContext .EXPECT ().GetConfiguration ().Return (config ).AnyTimes ()
4140 mockInvocationContext .EXPECT ().GetEnhancedLogger ().Return (& logger ).AnyTimes ()
4241 mockInvocationContext .EXPECT ().GetAnalytics ().Return (analytics ).AnyTimes ()
43- err = entryPointDI (mockInvocationContext , & logger , engine , authenticator )
44- err = entryPointDI (mockInvocationContext , & logger , engine , authenticator )
42+ err = AuthEntryPointDI (mockInvocationContext , & logger , engine , authenticator )
43+ err = AuthEntryPointDI (mockInvocationContext , & logger , engine , authenticator )
4544 assert .NoError (t , err )
4645 })
4746
4847 t .Run ("unhappy" , func (t * testing.T ) {
49- config .Set (authTypeParameter , nil )
48+ config .Set (AuthTypeParameter , nil )
5049 expectedErr := fmt .Errorf ("someting went wrong" )
5150 authenticator .EXPECT ().Authenticate ().Times (1 ).Return (expectedErr )
5251 mockInvocationContext := mocks .NewMockInvocationContext (mockCtl )
5352 mockInvocationContext .EXPECT ().GetConfiguration ().Return (config ).AnyTimes ()
5453 mockInvocationContext .EXPECT ().GetEnhancedLogger ().Return (& logger ).AnyTimes ()
5554 mockInvocationContext .EXPECT ().GetAnalytics ().Return (analytics ).AnyTimes ()
56- err = entryPointDI (mockInvocationContext , & logger , engine , authenticator )
55+ err = AuthEntryPointDI (mockInvocationContext , & logger , engine , authenticator )
5756 assert .Equal (t , expectedErr , err )
5857 })
5958}
@@ -77,27 +76,27 @@ func Test_auth_token(t *testing.T) {
7776 assert .NoError (t , err )
7877
7978 t .Run ("happy" , func (t * testing.T ) {
80- config .Set (authTypeParameter , auth .AUTH_TYPE_TOKEN )
79+ config .Set (AuthTypeParameter , auth .AUTH_TYPE_TOKEN )
8180 engine .EXPECT ().InvokeWithConfig (gomock .Any (), gomock .Any ())
8281 mockInvocationContext := mocks .NewMockInvocationContext (mockCtl )
8382 mockInvocationContext .EXPECT ().GetConfiguration ().Return (config ).AnyTimes ()
8483 mockInvocationContext .EXPECT ().GetEnhancedLogger ().Return (& logger ).AnyTimes ()
8584 mockInvocationContext .EXPECT ().GetAnalytics ().Return (analytics ).AnyTimes ()
8685
87- err = entryPointDI (mockInvocationContext , & logger , engine , authenticator )
86+ err = AuthEntryPointDI (mockInvocationContext , & logger , engine , authenticator )
8887 assert .NoError (t , err )
8988 })
9089
9190 t .Run ("automatically switch to token when API token is given" , func (t * testing.T ) {
92- config .Set (authTypeParameter , nil )
91+ config .Set (AuthTypeParameter , nil )
9392 config .Set (ConfigurationNewAuthenticationToken , "00000000-0000-0000-0000-000000000000" )
9493 engine .EXPECT ().InvokeWithConfig (gomock .Any (), gomock .Any ())
9594 mockInvocationContext := mocks .NewMockInvocationContext (mockCtl )
9695 mockInvocationContext .EXPECT ().GetConfiguration ().Return (config ).AnyTimes ()
9796 mockInvocationContext .EXPECT ().GetEnhancedLogger ().Return (& logger ).AnyTimes ()
9897 mockInvocationContext .EXPECT ().GetAnalytics ().Return (analytics ).AnyTimes ()
9998
100- err = entryPointDI (mockInvocationContext , & logger , engine , authenticator )
99+ err = AuthEntryPointDI (mockInvocationContext , & logger , engine , authenticator )
101100 assert .NoError (t , err )
102101 })
103102}
@@ -116,7 +115,7 @@ func Test_pat(t *testing.T) {
116115
117116 t .Run ("happy" , func (t * testing.T ) {
118117 config := configuration .NewWithOpts ()
119- config .Set (authTypeParameter , auth .AUTH_TYPE_PAT )
118+ config .Set (AuthTypeParameter , auth .AUTH_TYPE_PAT )
120119 config .Set (ConfigurationNewAuthenticationToken , pat )
121120
122121 config .Set (auth .CONFIG_KEY_OAUTH_TOKEN , "some-oauth-token" )
@@ -130,7 +129,7 @@ func Test_pat(t *testing.T) {
130129 engine .EXPECT ().GetConfiguration ().Return (config ).AnyTimes ()
131130 engine .EXPECT ().InvokeWithConfig (gomock .Any (), gomock .Any ())
132131
133- err := entryPointDI (mockInvocationContext , & logger , engine , authenticator )
132+ err := AuthEntryPointDI (mockInvocationContext , & logger , engine , authenticator )
134133 assert .NoError (t , err )
135134
136135 assert .Empty (t , config .GetString (auth .CONFIG_KEY_OAUTH_TOKEN ))
@@ -139,7 +138,7 @@ func Test_pat(t *testing.T) {
139138
140139 t .Run ("invalid pat should fail" , func (t * testing.T ) {
141140 config := configuration .NewWithOpts ()
142- config .Set (authTypeParameter , auth .AUTH_TYPE_PAT )
141+ config .Set (AuthTypeParameter , auth .AUTH_TYPE_PAT )
143142 config .Set (ConfigurationNewAuthenticationToken , pat )
144143
145144 config .Set (auth .CONFIG_KEY_OAUTH_TOKEN , "some-oauth-token" )
@@ -155,7 +154,7 @@ func Test_pat(t *testing.T) {
155154 mockWhoAmIError := fmt .Errorf ("mock whoami failure" )
156155 engine .EXPECT ().InvokeWithConfig (gomock .Any (), gomock .Any ()).Return (nil , mockWhoAmIError )
157156
158- err := entryPointDI (mockInvocationContext , & logger , engine , authenticator )
157+ err := AuthEntryPointDI (mockInvocationContext , & logger , engine , authenticator )
159158 assert .ErrorIs (t , err , mockWhoAmIError )
160159
161160 assert .Empty (t , config .GetString (auth .CONFIG_KEY_OAUTH_TOKEN ))
@@ -205,7 +204,7 @@ func Test_clearAllCredentialsBeforeAuth(t *testing.T) {
205204 for _ , tc := range testCases {
206205 t .Run (tc .name , func (t * testing.T ) {
207206 config := configuration .NewWithOpts ()
208- config .Set (authTypeParameter , tc .authType )
207+ config .Set (AuthTypeParameter , tc .authType )
209208 if tc .authType == auth .AUTH_TYPE_PAT {
210209 config .Set (ConfigurationNewAuthenticationToken , "snyk_uat.12345678.abcdefg-hijklmnop.qrstuvwxyz-123456" )
211210 }
@@ -221,7 +220,7 @@ func Test_clearAllCredentialsBeforeAuth(t *testing.T) {
221220
222221 tc .setupMocks ()
223222
224- err := entryPointDI (mockInvocationContext , & logger , engine , authenticator )
223+ err := AuthEntryPointDI (mockInvocationContext , & logger , engine , authenticator )
225224 assert .NoError (t , err )
226225
227226 // Verify both tokens are cleared regardless of auth type
0 commit comments