Skip to content

Commit

Permalink
ci: adds oauth mock (#873)
Browse files Browse the repository at this point in the history
* adds oauth mock

* forgot to commit this
  • Loading branch information
petethepig authored Feb 21, 2022
1 parent 2138213 commit 01a96a3
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"jest-image-snapshot": "^4.5.1",
"lint-staged": "^11.1.2",
"monaco-editor-webpack-plugin": "^1.9.0",
"oauth2-mock-server": "^4.3.0",
"optimize-css-assets-webpack-plugin": "^6.0.1",
"prettier": "^2.2.1",
"redux-mock-store": "^1.5.4",
Expand Down
20 changes: 20 additions & 0 deletions scripts/oauth-mock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### What is this?

This is a mock OAuth server for testing purposes. It allows you to run pyroscope with oauth enabled locally by mimicking gitlab oauth server.


### Usage

To run the mock server, run the following command:
```shell
node ./scripts/oauth-mock/oauth-mock.js
```

To run pyroscope with the right config run:
```shell
make build
bin/pyroscope server -config scripts/oauth-mock/pyroscope-config.yml
```

Then go to http://localhost:4040/ and pyroscope should send you to log in via GitLab (which is really just our mock in this case).

48 changes: 48 additions & 0 deletions scripts/oauth-mock/oauth-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
async function main() {
// eslint-disable-next-line global-require
const { OAuth2Server } = require('oauth2-mock-server');

const server = new OAuth2Server(undefined, undefined, {
endpoints: {
wellKnownDocument: '/.well-known/openid-configuration',
token: '/token',
jwks: '/jwks',
authorize: '/authorize',
userinfo: '/user',
revoke: '/revoke',
endSession: '/endSession',
introspect: '/introspect',
},
});

// hack to add /groups support to the mock server
server.service.requestHandler.get('/groups', (req, res) => {
res.status(200).json([{ path: 'allowed-group-example' }]);
});

server.service.once('beforeUserinfo', (userInfoResponse, req) => {
console.log('beforeUserinfo');
userInfoResponse.body = {
id: 1245,
email: 'test@test.com',
username: 'testuser',
avatarurl:
'https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50',
};
});

// Generate a new RSA key and add it to the keystore
await server.issuer.keys.generate('RS256');

// Start the server
await server.start(18080, 'localhost');
console.log('Issuer URL:', server.issuer.url); // -> http://localhost:8080

// Do some work with the server
// ...

// Stop the server
// return await server.stop();
}

main();
13 changes: 13 additions & 0 deletions scripts/oauth-mock/pyroscope-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
auth:
gitlab:
enabled: true
api-url: http://localhost:18080
auth-url: http://localhost:18080/authorize
token-url: http://localhost:18080/token
client-id: 42fe36a3c42334416f36f71049aa5efe
client-secret: 16f36f71049aa5efe42fe36a3c423344
# allowed-groups:
# - allowed-group-example
storage-path: tmp/oauth-mock-storage
log-level: debug
Loading

0 comments on commit 01a96a3

Please sign in to comment.