Skip to content

Commit 8e8a407

Browse files
Merge pull request #4845 from linuxfoundation/unicron-v3-apis-test-coverage-dev
Try to fix broken V3 token handling
2 parents 1b66340 + 7a1e556 commit 8e8a407

File tree

7 files changed

+84
-0
lines changed

7 files changed

+84
-0
lines changed

cla-backend-go/serverless.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ provider:
223223
AUTH0_DOMAIN: ${file(./env.json):auth0-domain, ssm:/cla-auth0-domain-${opt:stage}}
224224
AUTH0_CLIENT_ID: ${file(./env.json):auth0-clientId, ssm:/cla-auth0-clientId-${opt:stage}}
225225
AUTH0_USERNAME_CLAIM: ${file(./env.json):auth0-username-claim, ssm:/cla-auth0-username-claim-${opt:stage}}
226+
AUTH0_USERNAME_CLAIM_CLI: ${file(./env.json):auth0-username-cli-claim, ssm:/cla-auth0-username-claim-cli-${opt:stage}}
227+
AUTH0_EMAIL_CLAIM_CLI: ${file(./env.json):auth0-email-cli-claim, ssm:/cla-auth0-email-claim-cli-${opt:stage}}
228+
AUTH0_NAME_CLAIM_CLI: ${file(./env.json):auth0-name-cli-claim, ssm:/cla-auth0-name-claim-cli-${opt:stage}}
226229
AUTH0_ALGORITHM: ${file(./env.json):auth0-algorithm, ssm:/cla-auth0-algorithm-${opt:stage}}
227230
SF_INSTANCE_URL: ${file(./env.json):sf-instance-url, ssm:/cla-sf-instance-url-${opt:stage}}
228231
SF_CLIENT_ID: ${file(./env.json):sf-client-id, ssm:/cla-sf-consumer-key-${opt:stage}}

cla-backend/serverless.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ provider:
312312
AUTH0_DOMAIN: ${file(./env.json):auth0-domain, ssm:/cla-auth0-domain-${sls:stage}}
313313
AUTH0_CLIENT_ID: ${file(./env.json):auth0-clientId, ssm:/cla-auth0-clientId-${sls:stage}}
314314
AUTH0_USERNAME_CLAIM: ${file(./env.json):auth0-username-claim, ssm:/cla-auth0-username-claim-${sls:stage}}
315+
AUTH0_USERNAME_CLAIM_CLI: ${file(./env.json):auth0-username-cli-claim, ssm:/cla-auth0-username-claim-cli-${sls:stage}}
316+
AUTH0_EMAIL_CLAIM_CLI: ${file(./env.json):auth0-email-cli-claim, ssm:/cla-auth0-email-claim-cli-${sls:stage}}
317+
AUTH0_NAME_CLAIM_CLI: ${file(./env.json):auth0-name-cli-claim, ssm:/cla-auth0-name-claim-cli-${sls:stage}}
315318
AUTH0_ALGORITHM: ${file(./env.json):auth0-algorithm, ssm:/cla-auth0-algorithm-${sls:stage}}
316319
SF_INSTANCE_URL: ${file(./env.json):sf-instance-url, ssm:/cla-sf-instance-url-${sls:stage}}
317320
SF_CLIENT_ID: ${file(./env.json):sf-client-id, ssm:/cla-sf-consumer-key-${sls:stage}}

tests/functional/cypress/support/commands.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
207236
export 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+
'X-EMAIL': '[email protected]',
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+
233288
let bearerToken = '';
234289
export function getTokenKey() {
235290
const envToken = Cypress.env('TOKEN');

utils/get_dev_claims.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
aws --profile lfproduct-dev --region us-east-1 ssm get-parameter --name "/cla-auth0-username-claim-dev" --query "Parameter.Value" --output text
3+
aws --profile lfproduct-dev --region us-east-1 ssm get-parameter --name "/cla-auth0-username-claim-cli-dev" --query "Parameter.Value" --output text
4+
aws --profile lfproduct-dev --region us-east-1 ssm get-parameter --name "/cla-auth0-email-claim-cli-dev" --query "Parameter.Value" --output text
5+
aws --profile lfproduct-dev --region us-east-1 ssm get-parameter --name "/cla-auth0-name-claim-cli-dev" --query "Parameter.Value" --output text

utils/get_prod_claims.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
aws --profile lfproduct-prod --region us-east-1 ssm get-parameter --name "/cla-auth0-username-claim-prod" --query "Parameter.Value" --output text
3+
aws --profile lfproduct-prod --region us-east-1 ssm get-parameter --name "/cla-auth0-username-claim-cli-prod" --query "Parameter.Value" --output text
4+
aws --profile lfproduct-prod --region us-east-1 ssm get-parameter --name "/cla-auth0-email-claim-cli-prod" --query "Parameter.Value" --output text
5+
aws --profile lfproduct-prod --region us-east-1 ssm get-parameter --name "/cla-auth0-name-claim-cli-prod" --query "Parameter.Value" --output text

utils/restore_dev_claims.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
# This is needed for V3 CLA Auth0 setup
3+
aws --profile lfproduct-dev --region us-east-1 ssm put-parameter --name "/cla-auth0-username-claim-dev" --value "https://sso.linuxfoundation.org/claims/username" --type "String" --overwrite
4+
aws --profile lfproduct-dev --region us-east-1 ssm delete-parameter --name "/cla-auth0-username-claim-cli-dev"
5+
aws --profile lfproduct-dev --region us-east-1 ssm delete-parameter --name "/cla-auth0-email-claim-cli-dev"
6+
aws --profile lfproduct-dev --region us-east-1 ssm delete-parameter --name "/cla-auth0-name-claim-cli-dev"
7+
./utils/get_dev_claims.sh

utils/set_dev_claims.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
# This is needed for V3 CLA Auth0 setup
3+
aws --profile lfproduct-dev --region us-east-1 ssm put-parameter --name "/cla-auth0-username-claim-cli-dev" --value "http://lfx.dev/claims/username" --type "String" --overwrite
4+
aws --profile lfproduct-dev --region us-east-1 ssm put-parameter --name "/cla-auth0-email-claim-cli-dev" --value "http://lfx.dev/claims/email" --type "String" --overwrite
5+
aws --profile lfproduct-dev --region us-east-1 ssm put-parameter --name "/cla-auth0-name-claim-cli-dev" --value "http://lfx.dev/claims/username" --type "String" --overwrite
6+
./utils/get_dev_claims.sh

0 commit comments

Comments
 (0)