1
- import { CloudAuthRequest , CloudAuthResponse , CloudAuthStatus } from 'src/modules/cloud/auth/models' ;
1
+ import {
2
+ CloudAuthIdpType , CloudAuthRequest , CloudAuthResponse , CloudAuthStatus ,
3
+ } from 'src/modules/cloud/auth/models' ;
2
4
import { mockSessionMetadata } from 'src/__mocks__/common' ;
3
5
4
6
export const mockCloudAuthCode = 'ac_p6vA6A5tF36Jf6twH2cBOqtt7n' ;
@@ -43,6 +45,12 @@ export const mockCloudAuthGithubTokenParams = {
43
45
idpType : 'github' ,
44
46
} ;
45
47
48
+ export const mockCloudAuthSsoTokenParams = {
49
+ ...mockCloudAuthGoogleTokenParams ,
50
+ state : 'state_p6vA6A5tF36Jf6twH2cBOqtt7ssp' ,
51
+ idpType : 'sso' ,
52
+ } ;
53
+
46
54
export const mockCloudAuthGoogleRequest = Object . assign ( new CloudAuthRequest ( ) , {
47
55
...mockCloudAuthGoogleTokenParams ,
48
56
sessionMetadata : {
@@ -52,6 +60,15 @@ export const mockCloudAuthGoogleRequest = Object.assign(new CloudAuthRequest(),
52
60
createdAt : new Date ( ) ,
53
61
} ) ;
54
62
63
+ export const mockCloudAuthSsoRequest = Object . assign ( new CloudAuthRequest ( ) , {
64
+ ...mockCloudAuthGoogleRequest ,
65
+ ...mockCloudAuthSsoTokenParams ,
66
+ tokenManager : { storage : { } } ,
67
+ createdAt : new Date ( ) ,
68
+ idpType : CloudAuthIdpType . Sso ,
69
+ idp : 'idp_p6vA6A5tF36Jf6twH2cBOqtSSO' ,
70
+ } ) ;
71
+
55
72
export const mockCloudAuthGoogleAuthUrl = `${ mockCloudAuthGoogleRequest . issuer } `
56
73
+ `/${ mockCloudAuthGoogleRequest . authorizeUrl } `
57
74
+ `?client_id=${ mockCloudAuthGoogleRequest . clientId } `
@@ -66,6 +83,20 @@ export const mockCloudAuthGoogleAuthUrl = `${mockCloudAuthGoogleRequest.issuer}`
66
83
+ `&${ new URLSearchParams ( { scope : mockCloudAuthGoogleRequest . scopes . join ( ' ' ) } ) . toString ( ) } `
67
84
+ '&prompt=login' ;
68
85
86
+ export const mockCloudAuthSsoAuthUrl = `${ mockCloudAuthSsoRequest . issuer } `
87
+ + `/${ mockCloudAuthSsoRequest . authorizeUrl } `
88
+ + `?client_id=${ mockCloudAuthSsoRequest . clientId } `
89
+ + `&${ new URLSearchParams ( { redirect_uri : mockCloudAuthSsoRequest . redirectUri } ) . toString ( ) } `
90
+ + `&response_type=${ mockCloudAuthSsoRequest . responseType } `
91
+ + `&response_mode=${ mockCloudAuthSsoRequest . responseMode } `
92
+ + `&idp=${ mockCloudAuthSsoRequest . idp } `
93
+ + `&state=${ mockCloudAuthSsoRequest . state } `
94
+ + `&nonce=${ mockCloudAuthSsoRequest . nonce } `
95
+ + `&code_challenge_method=${ mockCloudAuthSsoRequest . codeChallengeMethod } `
96
+ + `&code_challenge=${ mockCloudAuthSsoRequest . codeChallenge } `
97
+ + `&${ new URLSearchParams ( { scope : mockCloudAuthSsoRequest . scopes . join ( ' ' ) } ) . toString ( ) } `
98
+ + '&prompt=login' ;
99
+
69
100
export const mockCloudAuthGoogleTokenUrl = `${ mockCloudAuthGoogleRequest . issuer } `
70
101
+ `/${ mockCloudAuthGoogleRequest . tokenUrl } `
71
102
+ `?client_id=${ mockCloudAuthGoogleRequest . clientId } `
@@ -83,6 +114,12 @@ export const mockCloudAuthGoogleRevokeTokenUrl = `${mockCloudAuthGoogleRequest.i
83
114
+ `&token_type_hint=${ mockCloudRevokeRefreshTokenHint } `
84
115
+ `&token=${ mockCloudRefreshToken } ` ;
85
116
117
+ export const mockCloudAuthSsoRevokeTokenUrl = `${ mockCloudAuthSsoRequest . issuer } `
118
+ + `/${ mockCloudAuthGoogleIdpConfig . revokeTokenUrl } `
119
+ + `?client_id=${ mockCloudAuthSsoRequest . clientId } `
120
+ + `&token_type_hint=${ mockCloudRevokeRefreshTokenHint } `
121
+ + `&token=${ mockCloudRefreshToken } ` ;
122
+
86
123
export const mockCloudAuthGoogleRenewTokenUrl = `${ mockCloudAuthGoogleRequest . issuer } `
87
124
+ `/${ mockCloudAuthGoogleIdpConfig . tokenUrl } `
88
125
+ `?client_id=${ mockCloudAuthGoogleRequest . clientId } `
@@ -91,6 +128,14 @@ export const mockCloudAuthGoogleRenewTokenUrl = `${mockCloudAuthGoogleRequest.is
91
128
+ `&${ new URLSearchParams ( { scope : mockCloudAuthGoogleRequest . scopes . join ( ' ' ) } ) . toString ( ) } `
92
129
+ `&refresh_token=${ mockCloudRefreshToken } ` ;
93
130
131
+ export const mockCloudAuthSsoRenewTokenUrl = `${ mockCloudAuthSsoRequest . issuer } `
132
+ + `/${ mockCloudAuthGoogleIdpConfig . tokenUrl } `
133
+ + `?client_id=${ mockCloudAuthSsoRequest . clientId } `
134
+ + '&grant_type=refresh_token'
135
+ + `&${ new URLSearchParams ( { redirect_uri : mockCloudAuthSsoRequest . redirectUri } ) . toString ( ) } `
136
+ + `&${ new URLSearchParams ( { scope : mockCloudAuthSsoRequest . scopes . join ( ' ' ) } ) . toString ( ) } `
137
+ + `&refresh_token=${ mockCloudRefreshToken } ` ;
138
+
94
139
export const mockCloudAuthGithubRequest = Object . assign ( new CloudAuthRequest ( ) , {
95
140
...mockCloudAuthGithubTokenParams ,
96
141
sessionMetadata : {
@@ -160,6 +205,12 @@ export const mockGoogleIdpCloudAuthStrategy = jest.fn(() => ({
160
205
generateRenewTokensUrl : jest . fn ( ) . mockReturnValue ( new URL ( mockCloudAuthGoogleRenewTokenUrl ) ) ,
161
206
} ) ) ;
162
207
208
+ export const mockSsoIdpCloudAuthStrategy = jest . fn ( ( ) => ( {
209
+ generateAuthRequest : jest . fn ( ) . mockResolvedValue ( mockCloudAuthSsoRequest ) ,
210
+ generateRevokeTokensUrl : jest . fn ( ) . mockReturnValue ( new URL ( mockCloudAuthSsoRevokeTokenUrl ) ) ,
211
+ generateRenewTokensUrl : jest . fn ( ) . mockReturnValue ( new URL ( mockCloudAuthSsoRenewTokenUrl ) ) ,
212
+ } ) ) ;
213
+
163
214
export const mockCloudAuthService = jest . fn ( ( ) => ( {
164
215
renewTokens : jest . fn ( ) . mockResolvedValue ( undefined ) ,
165
216
} ) ) ;
0 commit comments