Skip to content

Commit

Permalink
test(e2e): default and empty values and required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent 34cd5e8 commit 72f2c5f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 56 deletions.
22 changes: 1 addition & 21 deletions test/e2e/cypress/integration/profiles/email/login/error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,7 @@ describe('Basic email profile with failing login flows', () => {
cy.get('input[name="password_identifier"]').type('i-do-not-exist')
cy.get('input[name="password"]').type('invalid-password')

let initial
cy.location().should((location) => {
initial = location.search
})

cy.clearAllCookies()
cy.submitPasswordForm()

// We end up at a new flow
if (app === 'express') {
cy.location().should((location) => {
expect(initial).to.not.be.empty
expect(location.search).to.not.eq(initial)
})

cy.location('pathname').should('include', '/error')
cy.get('code').should('contain.text', 'csrf_token')
} else {
cy.location('pathname').should('include', '/login')
cy.get('.Toastify').should('contain.text', 'A security violation was detected, please fill out the form again.')
}
cy.shouldHaveCsrfError({app})
})

it('fails when a disallowed return_to url is requested', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,7 @@ describe('Registration failures with email profile', () => {
.type('123456')
.should('have.value', '123456')

let initial
cy.location().should((location) => {
initial = location.search
})

cy.clearAllCookies()
cy.submitPasswordForm()

// We end up at a new flow
cy.location().should((location) => {
expect(location.search).to.not.eq(initial)
})
if (app === 'express') {
cy.location('pathname').should('include', '/error')
cy.get('code').should('contain.text', 'csrf_token')
} else {
cy.location('pathname').should('include', '/registration')
cy.get('.Toastify').should('contain.text', 'A security violation was detected, please fill out the form again.')
}
cy.shouldHaveCsrfError({app})
})

it('fails when a disallowed return_to url is requested', () => {
Expand Down Expand Up @@ -133,15 +115,38 @@ describe('Registration failures with email profile', () => {
it('should show an error when the website is too short', () => {
cy.get('input[name="traits.website"]').type('http://s')

// fixme https://github.com/ory/kratos/issues/368
cy.get('input[name="password"]').type(password)

cy.submitPasswordForm()
cy.get('*[data-testid^="ui/message"]').should(
'contain.text',
'length must be >= 10'
)
})

it('should show an error when required params are missing', () => {
cy.submitPasswordForm()
cy.get('*[data-testid^="ui/message"]').should(
'contain.text',
'Property website is missing.'
)
cy.get('*[data-testid^="ui/message"]').should(
'contain.text',
'Property email is missing.'
)
cy.get('*[data-testid^="ui/message"]').should(
'contain.text',
'Property password is missing.'
)
})

it('should show an error when the age is too high', () => {
cy.get('input[name="traits.age"]').type('600')

cy.submitPasswordForm()
cy.get('*[data-testid^="ui/message"]').should(
'contain.text',
'must be <= 300 but found 600'
)
})
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ context('Registration success with email profile', () => {
const email = gen.email()
const password = gen.password()
const website = 'https://www.ory.sh/'
const age = 30

cy.get('input[name="traits"]').should('not.exist')
cy.get('input[name="traits.email"]').type(email)
cy.get('input[name="traits.website').type(website)
cy.get('input[name="password"]').type(password)
cy.get('input[name="traits.website').type(website)
cy.get('input[name="traits.age"]').type(`${age}`)
cy.get('[type="checkbox"][name="traits.tos"]').click({force: true})

cy.get('button[type="submit"]').click()
cy.submitPasswordForm()
cy.get('pre').should('contain.text', email)

cy.getSession().should((session) => {
Expand All @@ -43,6 +46,33 @@ context('Registration success with email profile', () => {
expect(identity.schema_url).to.equal(`${APP_URL}/schemas/default`)
expect(identity.traits.website).to.equal(website)
expect(identity.traits.email).to.equal(email)
expect(identity.traits.age).to.equal(age)
expect(identity.traits.tos).to.equal(true)
})
})

it('should sign up with advanced form field values be logged in', () => {
const email = gen.email()
const password = gen.password()

cy.get('input[name="traits"]').should('not.exist')
cy.get('input[name="traits.email"]').type(email)
cy.get('input[name="password"]').type(password)
cy.get('input[name="website"]').type('')

cy.submitPasswordForm()
cy.get('pre').should('contain.text', email)

cy.getSession().should((session) => {
const {identity} = session
expect(identity.id).to.not.be.empty
expect(identity.verifiable_addresses).to.be.undefined
expect(identity.schema_id).to.equal('default')
expect(identity.schema_url).to.equal(`${APP_URL}/schemas/default`)
expect(identity.traits.website).to.equal('')
expect(identity.traits.email).to.equal(email)
expect(identity.traits.age).to.equal(0)
expect(identity.traits.tos).to.equal(false)
})
})

Expand All @@ -60,14 +90,13 @@ context('Registration success with email profile', () => {
cy.get('input[name="traits.email"]').type(email)
cy.get('input[name="traits.website').type(website)
cy.get('input[name="password"]').type(password)

cy.get('button[type="submit"]').click()
cy.submitPasswordForm()
cy.url().should('eq', 'https://www.ory.sh/')
})
})
})

describe('redirect for express app',() => {
describe('redirect for express app', () => {
it('should redirect to return_to after flow expires', () => {
// Wait for flow to expire
cy.useConfigProfile('email')
Expand All @@ -88,19 +117,19 @@ context('Registration success with email profile', () => {
cy.get('input[name="password"]').type(password)

cy.longRegisterLifespan()
cy.get('button[type="submit"]').click()
cy.submitPasswordForm()

cy.get('*[data-testid^="ui/message/"]').should(
'contain.text',
'The registration flow expired'
)
cy.get('*[data-testid^="ui/message/"]').should(
'contain.text',
'The registration flow expired'
)

// Try again with long lifespan set
cy.get('input[name="traits"]').should('not.exist')
cy.get('input[name="traits.email"]').type(email)
cy.get('input[name="traits.website').type(website)
cy.get('input[name="password"]').type(password)
cy.get('button[type="submit"]').click()
cy.submitPasswordForm()

cy.url().should('eq', 'https://www.ory.sh/')
})
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/profiles/email/identity.traits.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
},
"age": {
"title": "Age",
"type": "number"
"type": "number",
"maximum": 300
}
},
"required": [
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/profiles/mobile/identity.traits.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
},
"age": {
"title": "Age",
"type": "number"
"type": "number",
"maximum": 300
}
},
"required": [
Expand Down

0 comments on commit 72f2c5f

Please sign in to comment.