Skip to content

Commit

Permalink
make over of old tests and api tests;
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thuermann committed Mar 16, 2022
1 parent b806d81 commit 73d3731
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 89 deletions.
53 changes: 36 additions & 17 deletions cypress/integration/test.api.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
/* Here are the first API tests. one can find some hints about it in the
README.md. */

describe('OWASP juice shop - API', () => {

it.only('Login', () => {
cy.api({
method: 'POST',
url: '/rest/user/login',
body: {
email: 'mc.safesearch@juice-sh.op',
password: 'Mr. N00dles'
}
}).then(
(response) => {
expect(response.status).to.eq(200),
expect(response.body.authentication.umail).to.eq('mc.safesearch@juice-sh.op'),
cy.log(response.body.authentication.token).as('token'),
cy.log(response.duration).as('duration')
})
})
})
it('Login', () => {
cy.api({
method: 'POST',
url: '/rest/user/login',
body: {
email: 'mc.safesearch@juice-sh.op',
password: 'Mr. N00dles'
}
}).then(
(response) => {
expect(response.status).to.eq(200),
expect(response.body.authentication.umail).to.eq('mc.safesearch@juice-sh.op'),
cy.log(response.body.authentication.token)
.as('token'),
cy.log(response.duration)
.as('duration')
});
});

it('Get legal text', () => {
cy.api({
method: 'GET',
url: '/ftp/legal.md'
}).then(
(response) => {
expect(response.status).to.eq(200),
cy.log(response.body)
.as('legal'),
cy.log(response.duration)
.as('duration')
});
});
});
142 changes: 71 additions & 71 deletions cypress/integration/test.spec.js
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
describe("OWASP juice shop", () => {
before(() => {
cy.clearCookies();
cy.clearLocalStorage();
});

it("should visit some subpages", () => {
cy.visit("/#/about");
cy.visit("/#/photo-wall");
cy.request("/ftp/legal.md");
// cy.visit("/ftp/", { failOnStatusCode: false }); // TODO make it run again
});
/* I have revised the test cases. Now they are almost independent of each other,
except the first test is responsible for setting the cookies correctly for the
following ones. */

it("should close the welcome banner and cookie notice", () => {
cy.visit("/");
cy.get("button[aria-label='Close Welcome Banner']").click();
cy.get("a[aria-label='dismiss cookie message']").click();
describe("OWASP juice shop", () => {
before(() => {
cy.clearCookies();
cy.clearLocalStorage();
});
beforeEach(() => {
Cypress.Cookies.preserveOnce('cookieconsent_status',
'welcomebanner_status');
cy.visit("/");
});

it("should close the welcome banner and cookie notice", () => {
cy.get("button[aria-label='Close Welcome Banner']")
.click();
cy.get("a[aria-label='dismiss cookie message']")
.click();
});

it("should type in credentials, press the login button and be logged in",
() => {
cy.get("button[aria-label='Show the shopping cart']").should("not.exist");

cy.get("button#navbarAccount").click();
cy.get("button#navbarLoginButton").click();

cy.url().should("include", "login");

cy.get("#login-form").within(() => {
cy.get("#email").type("mc.safesearch@juice-sh.op");
cy.get("#password").type("Mr. N00dles");
cy.get("#rememberMe").click();

cy.get("#loginButton").click();
});

it("should navigate to login page", () => {
cy.get("button#navbarAccount").click();
cy.get("button#navbarLoginButton").click();
cy.get("button[aria-label='Show the shopping cart']").should("exist");
});

cy.url().should("include", "login");
});
it("should visit some subpages", () => {
cy.visit("/#/about");
cy.visit("/#/photo-wall");
});

it("should type in credentials, press the login button and be logged in", () => {
cy.get("button[aria-label='Show the shopping cart']").should("not.exist");
it("should open profile and add username", () => {
cy.get("button#navbarAccount").click();
cy.get("button#navbarLoginButton").click();

cy.get("#login-form").within(() => {
cy.get("#email").type("mc.safesearch@juice-sh.op");
cy.get("#password").type("Mr. N00dles");
cy.get("#rememberMe").click();
cy.url().should("include", "login");

cy.get("#loginButton").click();
});
cy.get("#login-form").within(() => {
cy.get("#email").type("mc.safesearch@juice-sh.op");
cy.get("#password").type("Mr. N00dles");
cy.get("#rememberMe").click();

cy.get("button[aria-label='Show the shopping cart']").should("exist");
cy.get("#loginButton").click();
});

it("should open profile and add username", () => {
cy.get("button#navbarAccount").click();
cy.get("button#navbarLoginButton").click();

cy.url().should("include", "login");
cy.get("button[aria-label='Show the shopping cart']").should("exist");

cy.get("#login-form").within(() => {
cy.get("#email").type("mc.safesearch@juice-sh.op");
cy.get("#password").type("Mr. N00dles");
cy.get("#rememberMe").click();
cy.visit("/profile");

cy.get("#loginButton").click();
});
cy.get("#username").clear().type("someUsername");
cy.get("#submit").click();

cy.get("button[aria-label='Show the shopping cart']").should("exist");
cy.visit("/rest/user/data-export", { failOnStatusCode: false })
});

cy.visit("/profile");

cy.get("#username").clear().type("someUsername");
cy.get("#submit").click();

cy.visit("/rest/user/data-export", { failOnStatusCode: false })
});

it("should open and close the item detail", () => {
cy.visit("/");
cy.get("button[aria-label='Close Welcome Banner']").click();
cy.get("a[aria-label='dismiss cookie message']").click();

cy.get(".ribbon-card").first().click();
cy.get("mat-dialog-container").should("exist");

cy.get("button[aria-label='Close Dialog']").click();
cy.get("mat-dialog-container").should("not.exist");
});
it("should open and close the item detail", () => {
cy.get(".ribbon-card").first().click();
cy.get("mat-dialog-container").should("exist");

it("should visit the score board", () => {
cy.visit("/#/score-board");
})
cy.get("button[aria-label='Close Dialog']").click();
cy.get("mat-dialog-container").should("not.exist");
});

it("should enter XSS payload into the search field", () => {
cy.get("button[aria-label='Close Welcome Banner']").click();
cy.get("a[aria-label='dismiss cookie message']").click();
it("should visit the score board", () => {
cy.visit("/#/score-board");
});

const payload = '<iframe src="javascript:alert(`xss`)">';
it("should enter XSS payload into the search field", () => {
const payload = '<iframe src="javascript:alert(`xss`)">';

cy.get("#searchQuery").click();
cy.get("#mat-input-0").clear().type(payload) + '{enter}';
})
cy.get("#searchQuery").click();
cy.get("#mat-input-0").clear().type(payload) + '{enter}';
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zapress",
"version": "1.18.0",
"description": "added api testing plugin and first api test, may also usefull for fast login",
"description": "updated cypress, added api testing plugin and first api tests, make over of old tests",
"main": "index.js",
"scripts": {
"start": "cypress open",
Expand Down

0 comments on commit 73d3731

Please sign in to comment.