@@ -204,6 +204,35 @@ export function shortenMiddle(str) {
204204 return `${ first } ...${ last } ` ;
205205}
206206
207+ export function getTokenForV3 ( ) {
208+ // V3 APIs require a token with specific claims: http://lfx.dev/claims/username and http://lfx.dev/claims/email
209+ // The token generation is the same as V4, but V3 expects the AUTH0_USERNAME_CLAIM to be set to "http://lfx.dev/claims/username"
210+ cy . task ( 'log' , '--> getting token by request for V3' ) ;
211+ return cy
212+ . request ( {
213+ method : 'POST' ,
214+ url : Cypress . env ( 'AUTH0_TOKEN_API' ) ,
215+ headers : {
216+ 'content-type' : 'application/json' ,
217+ } ,
218+ body : {
219+ grant_type : 'http://auth0.com/oauth/grant-type/password-realm' ,
220+ realm : 'Username-Password-Authentication' ,
221+ username : Cypress . env ( 'AUTH0_USER_NAME' ) ,
222+ password : Cypress . env ( 'AUTH0_PASSWORD' ) ,
223+ client_id : Cypress . env ( 'AUTH0_CLIENT_ID' ) ,
224+ audience : 'https://api-gw.dev.platform.linuxfoundation.org/' ,
225+ scope : 'access:api openid profile email' ,
226+ } ,
227+ } )
228+ . then ( ( response ) => {
229+ expect ( response . status ) . to . eq ( 200 ) ;
230+ const token = response . body . access_token ;
231+ cy . task ( 'log' , `--> got token ${ shortenMiddle ( token ) } from request for V3` ) ;
232+ return token ;
233+ } ) ;
234+ }
235+
207236export function getAPIBaseURL ( version ) {
208237 const local = Cypress . env ( 'LOCAL' ) ;
209238 switch ( version ) {
@@ -212,6 +241,12 @@ export function getAPIBaseURL(version) {
212241 return 'http://localhost:5001/v4/' ;
213242 }
214243 return `${ Cypress . env ( 'APP_URL' ) } cla-service/v4/` ;
244+ case 'v3' :
245+ if ( local ) {
246+ return 'http://localhost:5001/v3/' ;
247+ }
248+ // V3 is deployed on the legacy API endpoint, not the new cla-service endpoint
249+ return 'https://api.lfcla.dev.platform.linuxfoundation.org/v3/' ;
215250 default :
216251 cy . task ( 'log' , `--> unknown API version ${ version } ` ) ;
217252 }
@@ -230,6 +265,26 @@ export function getXACLHeader() {
230265 return { } ;
231266}
232267
268+ export function getXACLHeaders ( ) {
269+ // V3 APIs (which are actually V1 internally) use the same authentication as V4
270+ // They need both X-ACL headers and bearer tokens
271+ const xacl = Cypress . env ( 'XACL' ) ;
272+ if ( xacl ) {
273+ return {
274+ 'X-ACL' : xacl ,
275+ 'X-USERNAME' : 'lgryglicki' ,
276+ 277+ } ;
278+ }
279+ return { } ;
280+ }
281+
282+ export function getOAuth2Headers ( ) {
283+ // V3 APIs (which are actually V1 internally) use the same authentication as V4
284+ // They need both X-ACL headers and bearer tokens - just alias to getXACLHeaders
285+ return getXACLHeaders ( ) ;
286+ }
287+
233288let bearerToken = '' ;
234289export function getTokenKey ( ) {
235290 const envToken = Cypress . env ( 'TOKEN' ) ;
0 commit comments