Skip to content

Commit bdca4d7

Browse files
committed
Add todos for improving session validation
1 parent a3346dd commit bdca4d7

File tree

3 files changed

+1519
-830
lines changed

3 files changed

+1519
-830
lines changed

cypress/e2e/new-roles.cy.js

Lines changed: 84 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ describe('wip test refactor', () => {
4646
})
4747
.then(response => {
4848
expect(response.status).to.eq(200)
49-
console.log(
50-
'API Tokens response:',
51-
JSON.stringify(response.body, null, 2),
52-
)
53-
const cypressToken = response.body.data.find(
54-
token => token.name === 'cypress-test-token',
55-
)
56-
expect(cypressToken).to.exist
57-
apiToken = cypressToken.accessKey
58-
console.log('API Token set to:', apiToken)
49+
// console.log(
50+
// 'API Tokens response:',
51+
// JSON.stringify(response.body, null, 2),
52+
// )
53+
// const cypressToken = response.body.data.find(
54+
// token => token.name === 'cypress-test-token',
55+
// )
56+
// expect(cypressToken).to.exist
57+
// apiToken = cypressToken.accessKey
58+
// console.log('API Token set to:', apiToken)
5959
})
6060
})
6161

@@ -97,20 +97,57 @@ describe('wip test refactor', () => {
9797
})
9898
})
9999

100+
beforeEach(() => {
101+
cy.session(
102+
userCredentials.email,
103+
() => {
104+
cy.visit('http://localhost:1337/admin')
105+
cy.get('form').should('be.visible')
106+
cy.get('input[name="email"]').type(userCredentials.email)
107+
cy.get('input[name="password"]').type(userCredentials.password)
108+
cy.get('button[role="checkbox"]').click()
109+
cy.get('button[type="submit"]').click()
110+
111+
// TODO: assert `strapi_admin_refresh` cookie exists
112+
// cy.wait('@adminLogin')
113+
// .its('response.headers.set-cookie')
114+
// .should(
115+
// 'satisfy',
116+
// cookies =>
117+
// Array.isArray(cookies) &&
118+
// cookies.some(c => c.startsWith('strapi_admin_refresh=')),
119+
// )
120+
},
121+
{
122+
validate() {
123+
// TODO: uses `strapi_admin_refresh` cookie to validate login
124+
// cy.getCookie('strapi_admin_refresh').should('exist')
125+
126+
cy.wait(1000)
127+
cy.contains('Hello Admin No Access').should('be.visible')
128+
},
129+
},
130+
)
131+
})
132+
100133
it('works', () => {
101134
expect(true).to.be.true
135+
136+
// tests were green, so I added this to trigger hot reloading
137+
expect(false).to.be.false
102138
})
103139

104-
it('should not see the Meilisearch plugin in sidepanel', () => {
105-
cy.login({
106-
adminUrl: 'http://localhost:1337/admin',
107-
email: userCredentials.email,
108-
password: userCredentials.password,
109-
shouldContain: 'Hello Admin No Access',
110-
})
140+
it('should not see the plugin in sidepanel', () => {
111141
cy.visit('http://localhost:1337/admin')
112142
cy.get('nav').should('not.contain', 'a[aria-label="Meilisearch"]')
113143
})
144+
145+
it('cannot access the plugin page', () => {
146+
cy.visit('http://localhost:1337/admin/plugins/meilisearch')
147+
cy.contains(
148+
"You don't have the permissions to access that content",
149+
).should('be.visible')
150+
})
114151
})
115152

116153
// it('should be able to create a new admin user with admin token', () => {
@@ -211,35 +248,35 @@ describe('wip test refactor', () => {
211248
// })
212249

213250
// Cleanup tests - run after the main tests
214-
after(() => {
215-
// Clean up created user if it exists
216-
cy.window().then(win => {
217-
// Check if the alias exists before trying to get it
218-
if (Cypress.env('createdUserId')) {
219-
cy.request({
220-
method: 'DELETE',
221-
url: `http://localhost:1337/admin/users/${Cypress.env('createdUserId')}`,
222-
headers: {
223-
Authorization: `Bearer ${adminToken}`,
224-
},
225-
failOnStatusCode: false, // Don't fail if user doesn't exist
226-
})
227-
}
228-
})
251+
// after(() => {
252+
// // Clean up created user if it exists
253+
// cy.window().then(win => {
254+
// // Check if the alias exists before trying to get it
255+
// if (Cypress.env('createdUserId')) {
256+
// cy.request({
257+
// method: 'DELETE',
258+
// url: `http://localhost:1337/admin/users/${Cypress.env('createdUserId')}`,
259+
// headers: {
260+
// Authorization: `Bearer ${adminToken}`,
261+
// },
262+
// failOnStatusCode: false, // Don't fail if user doesn't exist
263+
// })
264+
// }
265+
// })
229266

230-
// Clean up created role if it exists
231-
cy.window().then(win => {
232-
// Check if the alias exists before trying to get it
233-
if (Cypress.env('createdRoleId')) {
234-
cy.request({
235-
method: 'DELETE',
236-
url: `http://localhost:1337/admin/roles/${Cypress.env('createdRoleId')}`,
237-
headers: {
238-
Authorization: `Bearer ${adminToken}`,
239-
},
240-
failOnStatusCode: false, // Don't fail if role doesn't exist
241-
})
242-
}
243-
})
244-
})
267+
// // Clean up created role if it exists
268+
// cy.window().then(win => {
269+
// // Check if the alias exists before trying to get it
270+
// if (Cypress.env('createdRoleId')) {
271+
// cy.request({
272+
// method: 'DELETE',
273+
// url: `http://localhost:1337/admin/roles/${Cypress.env('createdRoleId')}`,
274+
// headers: {
275+
// Authorization: `Bearer ${adminToken}`,
276+
// },
277+
// failOnStatusCode: false, // Don't fail if role doesn't exist
278+
// })
279+
// }
280+
// })
281+
// })
245282
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"@types/jest": "^29.5.12",
6363
"babel-jest": "^29.7.0",
6464
"concurrently": "^8.2.2",
65-
"cypress": "^14.0.1",
65+
"cypress": "^15.3.0",
6666
"eslint": "^8.2.0",
6767
"eslint-config-prettier": "^9.1.0",
6868
"eslint-plugin-cypress": "^2.12.1",

0 commit comments

Comments
 (0)