* write tests for invite-only mode and auth-providers * text edits * modify specs in light of new e2e database setup * Still working things out * Added the admin user name to the e2e fixture data. * Added testid for config sections. * Fixed up test to use cypress-testing-library APIs. * Fixed unsetting invite only mode, still need to reset it at end of test. * Small fix for local e2e development. * Complete all tests; generalize updateAdminConfig cypress command * correct spec * Complete implementation * Address code review comments * address code review comments #2 Co-authored-by: Nick Taylor <nick@dev.to>
137 lines
4.9 KiB
JavaScript
137 lines
4.9 KiB
JavaScript
describe('Authentication Section', () => {
|
|
beforeEach(() => {
|
|
cy.testSetup();
|
|
cy.fixture('users/adminUser.json').as('user');
|
|
|
|
cy.get('@user').then((user) => {
|
|
cy.loginUser(user).then(() => {
|
|
cy.updateAdminAuthConfig(user.username);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('invite-only mode setting', () => {
|
|
it('should disable email registration and all authorization providers when enabled', () => {
|
|
cy.fixture('users/adminUser.json').as('user');
|
|
|
|
cy.get('@user').then(({ username }) => {
|
|
cy.updateAdminAuthConfig(username, {
|
|
authProvidersToEnable: 'facebook',
|
|
facebookKey: 'somekey',
|
|
facebookSecret: 'somesecret',
|
|
}).then(() => {
|
|
cy.visit('/admin/config');
|
|
cy.findByTestId('authSectionForm').as('authSectionForm');
|
|
|
|
cy.get('@authSectionForm').findByText('Authentication').click();
|
|
cy.get('@authSectionForm')
|
|
.findByLabelText('Invite-only mode')
|
|
.should('not.be.checked')
|
|
.check();
|
|
|
|
cy.get('@authSectionForm')
|
|
.findByPlaceholderText('Confirmation text')
|
|
.type(
|
|
`My username is @${username} and this action is 100% safe and appropriate.`,
|
|
);
|
|
cy.get('@authSectionForm')
|
|
.findByText('Update Site Configuration')
|
|
.click();
|
|
|
|
cy.url().should('contains', '/admin/config');
|
|
|
|
// Page reloaded so need to get a new reference to the form.
|
|
cy.findByTestId('authSectionForm').as('authSectionForm');
|
|
|
|
cy.findByText('Site configuration was successfully updated.').should(
|
|
'be.visible',
|
|
);
|
|
|
|
cy.get('@authSectionForm').findByText('Authentication').click();
|
|
|
|
cy.get('@authSectionForm')
|
|
.findByLabelText('Invite-only mode')
|
|
.should('be.checked');
|
|
|
|
// Ensure that none of the authentication providers are enabled.
|
|
cy.findByLabelText('Email enabled').should('not.be.visible');
|
|
cy.findByLabelText('Facebook enabled').should('not.be.visible');
|
|
cy.findByLabelText('GitHub enabled').should('not.be.visible');
|
|
cy.findByLabelText('Twitter enabled').should('not.be.visible');
|
|
});
|
|
});
|
|
cy.visit('/signout_confirm');
|
|
|
|
cy.findByText('Yes, sign out').click();
|
|
cy.findByText('Create account').click();
|
|
|
|
cy.findByLabelText('Sign up with Email').should('not.exist');
|
|
cy.findByLabelText('Sign up with Facebook').should('not.exist');
|
|
cy.contains('invite only').should('be.visible');
|
|
});
|
|
});
|
|
|
|
describe('authentication providers settings', () => {
|
|
it('should display warning modal if provider keys are missing', () => {
|
|
cy.fixture('users/adminUser.json').as('user');
|
|
cy.get('@user').then(() => {
|
|
cy.visit('/admin/config');
|
|
cy.findByTestId('authSectionForm').as('authSectionForm');
|
|
|
|
cy.get('@authSectionForm').findByText('Authentication').click();
|
|
cy.get('#facebook-auth-btn').click();
|
|
cy.get('@user').then(({ username }) => {
|
|
cy.get('@authSectionForm')
|
|
.findByPlaceholderText('Confirmation text')
|
|
.type(
|
|
`My username is @${username} and this action is 100% safe and appropriate.`,
|
|
);
|
|
});
|
|
cy.get('@authSectionForm')
|
|
.findByText('Update Site Configuration')
|
|
.click();
|
|
|
|
cy.findByText('Setup not complete').should('be.visible');
|
|
cy.get('.crayons-modal__box__body > ul > li')
|
|
.contains('facebook')
|
|
.should('be.visible');
|
|
});
|
|
});
|
|
|
|
it('should not display warning modal if provider keys present', () => {
|
|
cy.fixture('users/adminUser.json').as('user');
|
|
|
|
cy.get('@user').then(() => {
|
|
cy.visit('/admin/config');
|
|
cy.findByTestId('authSectionForm').as('authSectionForm');
|
|
|
|
cy.get('@authSectionForm').findByText('Authentication').click();
|
|
cy.get('#facebook-auth-btn').click();
|
|
cy.get('#site_config_facebook_key').type('randomkey');
|
|
cy.get('#site_config_facebook_secret').type('randomsecret');
|
|
cy.get('@user').then(({ username }) => {
|
|
cy.get('@authSectionForm')
|
|
.findByPlaceholderText('Confirmation text')
|
|
.type(
|
|
`My username is @${username} and this action is 100% safe and appropriate.`,
|
|
);
|
|
});
|
|
cy.get('@authSectionForm')
|
|
.findByText('Update Site Configuration')
|
|
.click();
|
|
|
|
cy.url().should('contains', '/admin/config');
|
|
|
|
cy.findByText('Site configuration was successfully updated.').should(
|
|
'be.visible',
|
|
);
|
|
|
|
// Page reloaded so need to get a new reference to the form.
|
|
cy.findByTestId('authSectionForm').as('authSectionForm');
|
|
cy.get('@authSectionForm').findByText('Authentication').click();
|
|
|
|
cy.findByLabelText('Facebook enabled').should('be.visible');
|
|
});
|
|
});
|
|
});
|
|
});
|