-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Authentication strategies for registry (#324)
* Authentication strategies for registry * Tests * Add registry auth to other e2e tests
- Loading branch information
Showing
26 changed files
with
368 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
services/tests/e2e/authentication/__snapshots__/registry-jwt.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Authentication - Verify JWT Invalid Authentication Scheme 1`] = ` | ||
Object { | ||
"error": "Unauthorized", | ||
"message": "Unauthorized", | ||
"status": 401, | ||
"statusCode": 401, | ||
} | ||
`; | ||
|
||
exports[`Authentication - Verify JWT Invalid JWT 1`] = ` | ||
Object { | ||
"error": "Unauthorized", | ||
"message": "Unauthorized", | ||
"status": 401, | ||
"statusCode": 401, | ||
} | ||
`; | ||
|
||
exports[`Authentication - Verify JWT JWK uri is not resolved 1`] = ` | ||
Object { | ||
"error": "Unauthorized", | ||
"message": "Unauthorized", | ||
"status": 401, | ||
"statusCode": 401, | ||
} | ||
`; | ||
|
||
exports[`Authentication - Verify JWT Multiple audiences 1`] = ` | ||
Object { | ||
"plugins": Array [ | ||
Object { | ||
"name": "argument-injection-globals.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "async-function.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "crashing.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "folder-with-index-file", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "folder-with-node-module", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "folder-with-npm-module", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "folder-with-package-json-file", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "function.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "promise.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "single-file.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "transform-apollo-server-plugins", | ||
"version": "1.0.0", | ||
}, | ||
Object { | ||
"name": "transform-base-schema", | ||
"version": "1.0.0", | ||
}, | ||
Object { | ||
"name": "transform-resource-group.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "with-config.js", | ||
"version": "N/A", | ||
}, | ||
], | ||
} | ||
`; | ||
|
||
exports[`Authentication - Verify JWT Unexpected audience 1`] = ` | ||
Object { | ||
"error": "Unauthorized", | ||
"message": "Unauthorized", | ||
"status": 401, | ||
"statusCode": 401, | ||
} | ||
`; | ||
|
||
exports[`Authentication - Verify JWT Unknown issuer 1`] = ` | ||
Object { | ||
"error": "Unauthorized", | ||
"message": "Unauthorized", | ||
"status": 401, | ||
"statusCode": 401, | ||
} | ||
`; | ||
|
||
exports[`Authentication - Verify JWT Valid JWT 1`] = ` | ||
Object { | ||
"plugins": Array [ | ||
Object { | ||
"name": "argument-injection-globals.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "async-function.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "crashing.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "folder-with-index-file", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "folder-with-node-module", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "folder-with-npm-module", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "folder-with-package-json-file", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "function.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "promise.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "single-file.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "transform-apollo-server-plugins", | ||
"version": "1.0.0", | ||
}, | ||
Object { | ||
"name": "transform-base-schema", | ||
"version": "1.0.0", | ||
}, | ||
Object { | ||
"name": "transform-resource-group.js", | ||
"version": "N/A", | ||
}, | ||
Object { | ||
"name": "with-config.js", | ||
"version": "N/A", | ||
}, | ||
], | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { gql, GraphQLClient } from 'graphql-request'; | ||
import GraphQLErrorSerializer from '../../utils/graphql-error-serializer'; | ||
import { getToken, getInvalidToken } from '../../helpers/get-token'; | ||
|
||
const query = gql` | ||
query { | ||
plugins { | ||
name | ||
version | ||
} | ||
} | ||
`; | ||
|
||
describe('Authentication - Verify JWT', () => { | ||
const registryClient = new GraphQLClient('http://localhost:8090/graphql'); | ||
|
||
beforeAll(() => { | ||
expect.addSnapshotSerializer(GraphQLErrorSerializer); | ||
}); | ||
|
||
test('Valid JWT', async () => { | ||
const accessToken = await getToken({ scope: 'stitch-registry' }); | ||
registryClient.setHeader('Authorization', `Bearer ${accessToken}`); | ||
|
||
const result = await registryClient.request(query); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
test('Invalid JWT', async () => { | ||
const accessToken = await getInvalidToken(); | ||
registryClient.setHeader('Authorization', `Bearer ${accessToken}`); | ||
|
||
const result = await registryClient.request(query).catch(e => e.response); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
test('Invalid Authentication Scheme', async () => { | ||
const credentials = Buffer.from('user:pwd').toString('base64'); | ||
registryClient.setHeader('Authorization', `Basic ${credentials}`); | ||
|
||
const result = await registryClient.request(query).catch(e => e.response); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
test('Unknown issuer', async () => { | ||
const accessToken = await getInvalidToken({ issuer: 'http://microsoft.com' }); | ||
registryClient.setHeader('Authorization', `Bearer ${accessToken}`); | ||
|
||
const result = await registryClient.request(query).catch(e => e.response); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
test('Unexpected audience', async () => { | ||
const accessToken = await getInvalidToken({ audience: 'Stitch Other' }); | ||
registryClient.setHeader('Authorization', `Bearer ${accessToken}`); | ||
|
||
const result = await registryClient.request(query).catch(e => e.response); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
test('JWK uri is not resolved', async () => { | ||
const accessToken = await getToken({ tokenEndpoint: 'http://localhost:8071/connect/token' }); | ||
registryClient.setHeader('Authorization', `Bearer ${accessToken}`); | ||
|
||
const result = await registryClient.request(query).catch(e => e.response); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
|
||
test('Multiple audiences', async () => { | ||
const accessToken = await getToken({ | ||
scope: 'stitch-registry stitch-gateway', | ||
}); | ||
registryClient.setHeader('Authorization', `Bearer ${accessToken}`); | ||
|
||
const result = await registryClient.request(query); | ||
expect(result).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.