Skip to content

Commit

Permalink
oidc/login: add integration test (#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrsn authored Feb 12, 2025
1 parent 4af4f33 commit 1544035
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/integration/api/oidc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const { testService } = require('../setup');

describe('api: /oidc/...', () => {
if (process.env.TEST_AUTH === 'oidc') {
describe('GET /oidc/login', () => {
it('should redirect to IdP if no parameters are provided', testService(service =>
service.get('/v1/oidc/login')
.expect(307)
.then(({ text, headers }) => {
const expectedUrlPrefix = 'http://localhost:9898/auth?';
text.should.startWith('Temporary Redirect. Redirecting to ' + expectedUrlPrefix);
headers.location.should.startWith(expectedUrlPrefix);

const url = new URL(headers.location);
url.searchParams.sort();

[ ...url.searchParams.keys() ].should.eql([
'client_id',
'code_challenge',
'code_challenge_method',
'redirect_uri',
'resource',
'response_type',
'scope',
'state',
]);

url.searchParams.get('client_id').should.eql('odk-central-backend-dev');
url.searchParams.get('code_challenge_method').should.eql('S256');
url.searchParams.get('redirect_uri').should.eql('http://localhost:8989/v1/oidc/callback');
url.searchParams.get('resource').should.eql('http://localhost:8989/v1');
url.searchParams.get('response_type').should.eql('code');
url.searchParams.get('scope').should.eql('openid email');

url.searchParams.get('code_challenge').should.match(/^[a-zA-Z0-9-_]{43}$/);
url.searchParams.get('state' ).should.match(/^[a-zA-Z0-9-_]{43}:$/); // eslint-disable-line space-in-parens,no-multi-spaces
})));
});
} else { // OIDC not enabled
describe('GET /oidc/login', () => {
it('should not exist', testService(service =>
service.get('/v1/oidc/login')
.expect(404)));
});
}
});

0 comments on commit 1544035

Please sign in to comment.