Skip to content

Commit

Permalink
Merge pull request #723 from FoalTS/remove-auth0
Browse files Browse the repository at this point in the history
Remove Auth0 (and Cognito) tests
  • Loading branch information
LoicPoullain authored May 25, 2020
2 parents 28e0101 + 87fb9d3 commit a85d33f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 111 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ jobs:
node-version: [8, 10]

env:
AUTH0_DOMAIN: ${{ secrets.AUTH0_DOMAIN }}
AUTH0_AUDIENCE: ${{ secrets.AUTH0_AUDIENCE }}
AUTH0_TOKEN: ${{ secrets.AUTH0_TOKEN }}
SETTINGS_AWS_ACCESS_KEY_ID: ${{ secrets.SETTINGS_AWS_ACCESS_KEY_ID }}
SETTINGS_AWS_SECRET_ACCESS_KEY: ${{ secrets.SETTINGS_AWS_SECRET_ACCESS_KEY }}
NODE_VERSION: ${{ matrix.node-version }}
Expand Down
109 changes: 1 addition & 108 deletions packages/acceptance-tests/src/authentication/jwt.jwks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { join } from 'path';
// 3p
import { sign } from 'jsonwebtoken';
import * as superagent from 'superagent';
import * as request from 'supertest';

// FoalTS
import { Config, createApp, Get, HttpResponseOK } from '@foal/core';
import { createApp, Get, HttpResponseOK } from '@foal/core';
import { getRSAPublicKeyFromJWKS } from '@foal/jwks-rsa';
import { JWTRequired } from '@foal/jwt';

Expand Down Expand Up @@ -82,110 +81,4 @@ describe('[Authentication|JWT|JWKS] Users can be authenticated with a JWKS retre
}
});

it('from Auth0.', () => {
const domain = Config.get2('auth0.domain', 'string');
const audience = Config.get2('auth0.audience', 'string');
const token = Config.get2('auth0.token', 'string');

if (token === undefined) {
console.warn('AUTH0_TOKEN not defined. Skipping this test...');
return;
}

class AppController {

@Get('/api/users/me')
@JWTRequired({
secretOrPublicKey: getRSAPublicKeyFromJWKS({
cache: true,
jwksRequestsPerMinute: 5,
jwksUri: `https://${domain}/.well-known/jwks.json`,
rateLimit: true,
})
}, {
algorithms: [ 'RS256' ],
audience,
issuer: `https://${domain}/`,
})
getUser() {
return new HttpResponseOK({
name: 'Alix'
});
}

}

const app = createApp(AppController);

return request(app)
.get('/api/users/me')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.then(response => {
deepStrictEqual(response.body, {
name: 'Alix'
});
});
});

it('from AWS Cognito.', async () => {
const clientId = Config.get2('cognito.clientId', 'string');
const domain = Config.get2('cognito.domain', 'string');
const refreshToken = Config.get2('cognito.refreshToken', 'string');
let token: string;
const region = Config.get2('cognito.region', 'string');
const userPoolId = Config.get2('cognito.userPoolId', 'string');

if (refreshToken === undefined) {
console.warn('COGNITO_REFRESH_TOKEN not defined. Skipping this test...');
return;
}

try {
const { body } = await superagent
.post(`https://${domain}.auth.${region}.amazoncognito.com/oauth2/token`)
.send('grant_type=refresh_token')
.send(`client_id=${clientId}`)
.send(`refresh_token=${refreshToken}`);
token = body.id_token;
} catch (error) {
throw new Error('Requesting a new access token failed.');
}

class AppController {

@Get('/api/users/me')
@JWTRequired({
secretOrPublicKey: getRSAPublicKeyFromJWKS({
cache: true,
jwksRequestsPerMinute: 5,
jwksUri: `https://cognito-idp.${region}.amazonaws.com/${userPoolId}/.well-known/jwks.json`,
rateLimit: true,
})
}, {
algorithms: [ 'RS256' ],
audience: clientId,
issuer: `https://cognito-idp.${region}.amazonaws.com/${userPoolId}`,
})
getUser() {
return new HttpResponseOK({
name: 'Alix'
});
}

}

const app = createApp(AppController);

return request(app)
.get('/api/users/me')
.set('Authorization', 'Bearer ' + token)
.expect(200)
.then(response => {
deepStrictEqual(response.body, {
name: 'Alix'
});
});
});

});

0 comments on commit a85d33f

Please sign in to comment.