Skip to content
Snippets Groups Projects
auth.cy.ts 5.98 KiB
Newer Older
tzanmix's avatar
tzanmix committed
describe('user authentication', () => {
    beforeEach(() => {
        cy.visit(window.location.origin);
tzanmix's avatar
tzanmix committed
        
tzanmix's avatar
tzanmix committed
    })
    //edit profile bug
    it('should block unauthenticated user from entering a protected route', () => {
tzanmix's avatar
tzanmix committed
        cy.fixture("routes.json").then((data) => {
            cy.log(data.routes);
            // cy.wrap(data.routes).as("protectedRoutes");
            for(let route of data.routes) {
                cy.intercept(route);
                cy.log(route);
                cy.visit(route);
                cy.location("pathname").should("equal", "/");
            }
        });
        
tzanmix's avatar
tzanmix committed
    });

    it('should display login errors when nothing is typed', () => {
        cy.get(':nth-child(1) > .nav-link').click();
        cy.location("pathname").should("equal", '/services');
        cy.get('.btn').should("contain", "Sign In").click();
        cy.origin('https://portal.openslice.eu', () => {
            cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
            cy.get('#kc-login').click();
            cy.get('#input-error').should('be.visible').and('contain','Invalid username or password.');
            cy.get('[aria-invalid="true"]').should('have.length', 2); //the 2 input fields should have selector aria-invalid = 'true'
            
        });
        
    });

    it('should display login errors when credentials are wrong', () => {
        cy.get(':nth-child(1) > .nav-link').click();
        cy.location("pathname").should("equal", '/services');
        cy.get('.btn').should("contain", "Sign In").click();
        cy.origin('https://portal.openslice.eu', () => {
            
            cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
            
            cy.get('#username').type('test').blur();
            cy.get('#password').type('test').blur();
            cy.get('#kc-login').click();
            cy.get('#input-error').should('be.visible').and('contain','Invalid username or password.');
            cy.get('[aria-invalid="true"]').should('have.length', 2); //the 2 input fields should have selector aria-invalid = 'true'
            
        });
    });

    it('should login, logout', () => {
tzanmix's avatar
tzanmix committed
        
tzanmix's avatar
tzanmix committed
        cy.loginPath(':nth-child(2) > .container > .row > :nth-child(2) > a > .btn', '/services');
        cy.get('#navbarDropdown2').click();
        cy.window().then((win) => {
            expect(win.localStorage.getItem('access_token')).to.exist;
        })
        
        cy.get(':nth-child(2) > .dropdown > .dropdown-menu > :nth-child(8)').click();
        cy.location("pathname").should("equal", "/");
    });

tzanmix's avatar
tzanmix committed
    it('forget password should work', () => {
tzanmix's avatar
tzanmix committed
        cy.get(':nth-child(1) > .nav-link').click();
        cy.location("pathname").should("equal", '/services');
        cy.get('.btn').should("contain", "Sign In").click();
        cy.origin('https://portal.openslice.eu', () => {
            
            cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
            cy.get(':nth-child(2) > span > a').click();
            cy.location("pathname").should("equal", "/auth/realms/openslice/login-actions/reset-credentials");
            cy.get('#username').should('exist');
            
        });
    });

    context('register form', () => {
        beforeEach(() => {
            cy.get(':nth-child(1) > .nav-link').click();
            cy.location("pathname").should("equal", '/services');
            cy.get('.btn').should("contain", "Sign In").click();
            cy.origin('https://portal.openslice.eu', () => {
                
                cy.location("pathname").should("equal", "/auth/realms/openslice/protocol/openid-connect/auth");
                cy.get('#kc-registration > span > a').click();
                cy.location("pathname").should("equal", "/auth/realms/openslice/login-actions/registration");
                
            });
        })
        it('register form should not be empty when submitted', () => {
            
            cy.origin('https://portal.openslice.eu/auth/realms/openslice/login-actions/registration', () => {
    
                cy.get('.pf-c-button').click();
                cy.get('#input-error-firstname').should('exist').and('contain', 'Please specify first name.');
                cy.get('#input-error-lastname').should('exist').and('contain', 'Please specify last name.');
                cy.get('#input-error-email').should('exist').and('contain', 'Please specify email.');
                cy.get('#input-error-username').should('exist').and('contain', 'Please specify username.');
                cy.get('#input-error-password').should('exist').and('contain', 'Please specify password.');
            });
            
        });

        it('invalid email', () => {
            cy.origin('https://portal.openslice.eu/auth/realms/openslice/login-actions/registration', () => {
                
                cy.get('#email').type('email');
                cy.get('.pf-c-button').click();
                cy.get('#input-error-email').should('exist').and('contain','Invalid email address.');
                cy.get('#email').type('@example.com');
                cy.get('.pf-c-button').click();
                cy.get('#input-error-email').should('not.exist');
            });
        });

        it('confirm password field should be the same with password', () => {
            cy.origin('https://portal.openslice.eu/auth/realms/openslice/login-actions/registration', () => {
                cy.get('#password').type('123');
                cy.get('#password-confirm').type('1234');
                cy.get('.pf-c-button').click();
                cy.get('#input-error-password-confirm').should('exist').and('contain',"Password confirmation doesn't match.");
                cy.get('#password').type('123');
                cy.get('#password-confirm').type('123');
                cy.get('.pf-c-button').click();
                cy.get('#input-error-password-confirm').should('not.exist');
            });
        });


    })
    
})