Skip to content

Commit 47d7896

Browse files
committed
Cypress tests for OAuth login
1 parent d048d1f commit 47d7896

File tree

4 files changed

+67
-6
lines changed

4 files changed

+67
-6
lines changed

backend/internal/jobqueue/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestShutdown(t *testing.T) {
3333
err := Shutdown()
3434
require.Nil(t, err, "Shutdown should not return an error when jobqueue is started")
3535

36+
// nolint: gosimple
3637
select {
3738
case <-ctx.Done():
3839
switch ctx.Err() {

docker/ci/postgres/authentik.sql.gz

-8.23 KB
Binary file not shown.

test/cypress/e2e/api/Ldap.cy.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
/// <reference types="cypress" />
22

3-
const { curry } = require("lodash");
4-
5-
// WIP
6-
73
describe('LDAP with Authentik', () => {
84
let token;
95
if (Cypress.env('stack') === 'postgres') {
106

117
before(() => {
12-
cy.task('log', 'STACK IS: ' + Cypress.env('stack'));
13-
148
cy.resetUsers();
159
cy.getToken().then((tok) => {
1610
token = tok;

test/cypress/e2e/api/OAuth.cy.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/// <reference types="cypress" />
2+
3+
describe('OAuth with Authentik', () => {
4+
let token;
5+
if (Cypress.env('stack') === 'postgres') {
6+
7+
before(() => {
8+
cy.resetUsers();
9+
cy.getToken().then((tok) => {
10+
token = tok;
11+
12+
cy.task('backendApiPut', {
13+
token: token,
14+
path: '/api/settings/oauth-auth',
15+
data: {
16+
value: {
17+
client_id: 'U5gCy0ymU8OofWS4nmkAPugCbWkFkkPztap38ReD',
18+
client_secret: '9ZFClxwp7LzbfhIDk7k9DngQNQfwDAYqPrQMGXjFumCvQZATtXCwme20o0TnLP6uEHUkKqEFOInhxp01gVeaHCLW83iTK4PonoUnpFnXgyZAcu0H3zBxxOkVtRwACaoW',
19+
authorization_url: 'http://authentik-ldap:9000/application/o/authorize/',
20+
resource_url: 'http://authentik-ldap:9000/application/o/userinfo/',
21+
token_url: 'http://authentik-ldap:9000/application/o/token/',
22+
logout_url: 'http://authentik-ldap:9000/application/o/npm3/end-session/',
23+
identifier: 'preferred_username',
24+
scopes: [],
25+
auto_create_user: true
26+
}
27+
}
28+
}).then((data) => {
29+
cy.validateSwaggerSchema('put', 200, '/settings/{name}', data);
30+
expect(data.result).to.have.property('id');
31+
expect(data.result.id).to.be.greaterThan(0);
32+
});
33+
34+
cy.task('backendApiPut', {
35+
token: token,
36+
path: '/api/settings/auth-methods',
37+
data: {
38+
value: [
39+
'local',
40+
'oauth'
41+
]
42+
}
43+
}).then((data) => {
44+
cy.validateSwaggerSchema('put', 200, '/settings/{name}', data);
45+
expect(data.result).to.have.property('id');
46+
expect(data.result.id).to.be.greaterThan(0);
47+
});
48+
});
49+
});
50+
51+
it('Should log in with OAuth', function() {
52+
cy.task('backendApiGet', {
53+
token: token,
54+
path: '/oauth/login?redirect_base=http%3A%2F%2Ffullstack%3A81',
55+
}).then((data) => {
56+
expect(data).to.have.property('result');
57+
cy.visit(data.result);
58+
cy.get('input[name="uidField"]').type('cypress');
59+
cy.get('button[type="submit"]').click();
60+
cy.get('input[name="password"]').type('fqXBfUYqHvYqiwBHWW7f');
61+
cy.get('button[type="submit"]').click();
62+
cy.url().should('match', /fullstack/)
63+
});
64+
});
65+
}
66+
});

0 commit comments

Comments
 (0)