Skip to content

Commit bbea8d7

Browse files
committed
added tests for change password
1 parent 0bb780d commit bbea8d7

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
import { METHOD, STATUS_CODE } from "../../../support/api/api-const";
2+
import API from "../../../support/ApiUrls";
3+
4+
context("Update password", { tags: ['accounts', 'firstPool', 'all'] }, () => {
5+
const name = "TestUserRegistration";
6+
7+
it("Change password", () => {
8+
cy.request({
9+
method: METHOD.POST,
10+
url: API.ApiServer + API.ChangePassword,
11+
body: {
12+
username: name,
13+
oldPassword: "test",
14+
newPassword: "test1"
15+
}
16+
}).then((response) => {
17+
expect(response.status).to.eq(STATUS_CODE.OK);
18+
expect(response.body).to.have.property("username", name);
19+
expect(response.body).to.have.property("role", "USER");
20+
}).then(() => {
21+
cy.request({
22+
method: METHOD.POST,
23+
url: API.ApiServer + API.AccountsLogin,
24+
body: {
25+
username: name,
26+
password: "test1"
27+
}
28+
}).then((response) => {
29+
expect(response.status).to.eq(STATUS_CODE.OK);
30+
expect(response.body).to.have.property("username", name);
31+
expect(response.body).to.have.property("role", "USER");
32+
});
33+
cy.request({
34+
method: METHOD.POST,
35+
url: API.ApiServer + API.AccountsLogin,
36+
body: {
37+
username: name,
38+
password: "test"
39+
},
40+
failOnStatusCode: false
41+
}).then((response) => {
42+
expect(response.status).to.eq(STATUS_CODE.UNAUTHORIZED);
43+
});
44+
});
45+
});
46+
47+
it("Change password without body - Negative", () => {
48+
cy.request({
49+
method: METHOD.POST,
50+
url: API.ApiServer + API.ChangePassword,
51+
failOnStatusCode: false
52+
}).then((response) => {
53+
expect(response.status).to.eq(STATUS_CODE.UNPROCESSABLE);
54+
})
55+
});
56+
57+
it("Change password with wrong password body - Negative", () => {
58+
cy.request({
59+
method: METHOD.POST,
60+
url: API.ApiServer + API.ChangePassword,
61+
body: {
62+
username: name,
63+
oldPassword: "test",
64+
newPassword: "test2"
65+
},
66+
failOnStatusCode: false
67+
}).then((response) => {
68+
expect(response.status).to.eq(STATUS_CODE.UNAUTHORIZED);
69+
})
70+
});
71+
72+
it('Change password without username - Negative', () => {
73+
cy.request({
74+
method: METHOD.POST,
75+
url: API.ApiServer + API.ChangePassword,
76+
body: {
77+
oldPassword: "test",
78+
newPassword: "test1"
79+
},
80+
failOnStatusCode: false
81+
}).then((response) => {
82+
expect(response.status).to.eq(STATUS_CODE.UNPROCESSABLE);
83+
})
84+
});
85+
86+
it('Change password without old password - Negative', () => {
87+
cy.request({
88+
method: METHOD.POST,
89+
url: API.ApiServer + API.ChangePassword,
90+
body: {
91+
username: name,
92+
newPassword: "test1"
93+
},
94+
failOnStatusCode: false
95+
}).then((response) => {
96+
expect(response.status).to.eq(STATUS_CODE.UNPROCESSABLE);
97+
})
98+
});
99+
100+
it('Change password with wrong username - Negative', () => {
101+
cy.request({
102+
method: METHOD.POST,
103+
url: API.ApiServer + API.ChangePassword,
104+
body: {
105+
username: name + "fdsafds",
106+
oldPassword: "test",
107+
newPassword: "test1"
108+
},
109+
failOnStatusCode: false
110+
}).then((response) => {
111+
expect(response.status).to.eq(STATUS_CODE.UNAUTHORIZED);
112+
})
113+
});
114+
115+
it('Change password with sql infection - Negative', () => {
116+
cy.request({
117+
method: METHOD.POST,
118+
url: API.ApiServer + API.ChangePassword,
119+
body: {
120+
username: 'select * from users where id = 1 or 1=1',
121+
oldPassword: "test",
122+
newPassword: "test1"
123+
},
124+
failOnStatusCode: false
125+
}).then((response) => {
126+
expect(response.status).to.eq(STATUS_CODE.UNAUTHORIZED);
127+
})
128+
});
129+
});

e2e-tests/cypress/support/ApiUrls.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const API = {
44
//Accounts
55
Accounts: "accounts/",
66
AccountsLogin: "accounts/login/",
7+
ChangePassword: "accounts/change-password/",
78
AccessToken: "accounts/access-token/",
89
RootAuthorities: "accounts/root-authorities",
910
Installer: "accounts/installer",

0 commit comments

Comments
 (0)