|
| 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