@webship-js/codeigniter-steps 0.0.0-stage → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ @development
2
+ Feature: The debug toolbar and the debug page, in development
3
+ As a developer of the app
4
+ I want the debug toolbar and the debug page while the app runs in development
5
+ So that I see what a page did, and the checks for a live app see a real debug page
6
+
7
+ # A lane of its own: the app runs in the development environment for it
8
+ # (php spark env development) and in production again after (php spark env production).
9
+ # The default run leaves this feature out (tags).
10
+
11
+ Scenario: The pages of an app in development carry the debug toolbar
12
+ Given I am an anonymous user
13
+ When I go to the homepage
14
+ Then I should see the welcome page
15
+ And the page should say it runs in the "development" environment
16
+ And I should see the debug toolbar
17
+
18
+ Scenario: A panel of the debug toolbar shows what the page did
19
+ Given I am an anonymous user
20
+ When I go to "/login"
21
+ And I open the "Routes" panel of the debug toolbar
22
+ Then the "Routes" panel of the debug toolbar should show "LoginController::loginView"
23
+ And the "Routes" panel of the debug toolbar should show "TestFixtures::account"
24
+ When I open the "Config" panel of the debug toolbar
25
+ Then the "Config" panel of the debug toolbar should show "Environment: development"
26
+ And the "Config" panel of the debug toolbar should not show "Environment: production"
27
+
28
+ Scenario: The auth panel of the debug toolbar names the signed-in account
29
+ Given I am a logged in user with the "developer" user
30
+ When I go to "/account"
31
+ And I open the "Auth" panel of the debug toolbar
32
+ Then the "Auth" panel of the debug toolbar should show "developer@example.com"
33
+
34
+ @js-off
35
+ Scenario: An error nothing catches shows the debug page, and the check sees it
36
+ Given I am an anonymous user
37
+ When I go to "/test-fixtures/server-error"
38
+ Then the response status code should be 500
39
+ And the page should show debug information
40
+ And the page should say it runs in the "development" environment
41
+ And I should not see the debug toolbar
42
+
43
+ @js-off
44
+ Scenario: An address the app does not have tells how it was routed
45
+ Given I am an anonymous user
46
+ When I go to "/no-such-page-of-the-app"
47
+ Then I should see the 404 error page
48
+ And the page should show debug information
49
+
50
+ @js-off
51
+ Scenario: A form whose security token is out of date is refused with the 403 debug page
52
+ Given I am an anonymous user
53
+ When I go to "/login"
54
+ And I fill in "Email Address" with the email of "user"
55
+ And I fill in "Password" with the password of "user"
56
+ And the security token of the form expires
57
+ And I click the "Login" button
58
+ Then I should see the 403 error page
59
+ And I should see "The action you requested is not allowed."
@@ -0,0 +1,36 @@
1
+ @forgery
2
+ Feature: Forms sent from elsewhere, and out of date
3
+ As an account of the app
4
+ I want the app to take a form only from its own pages, with a token it issued
5
+ So that another site cannot act for me, and an old form cannot be replayed
6
+
7
+ @critical
8
+ Scenario: A login form sent from a page of another site does not log the browser in
9
+ Given I am an anonymous user
10
+ When I go to "/login"
11
+ And a page of another site sends the login form of "user" to "/login"
12
+ Then I should not be logged in
13
+
14
+ Scenario: A login form whose security token is out of date is refused
15
+ Given I am an anonymous user
16
+ When I go to "/login"
17
+ And I fill in "Email Address" with the email of "user"
18
+ And I fill in "Password" with the password of "user"
19
+ And the security token of the form expires
20
+ And I click the "Login" button
21
+ Then I should be on "/login"
22
+ And I should see the error message "The action you requested is not allowed."
23
+ And I should not be logged in
24
+
25
+ Scenario: A registration form whose security token is out of date is refused
26
+ Given I am an anonymous user
27
+ When I go to "/register"
28
+ And I fill in "Email Address" with the email of "user"
29
+ And I fill in "Username" with "new.person"
30
+ And I fill in "Password" with "Strong-Pass-2026!"
31
+ And I fill in "Password (again)" with "Strong-Pass-2026!"
32
+ And the security token of the form expires
33
+ And I click the "Register" button
34
+ Then I should be on "/register"
35
+ And I should see the error message "The action you requested is not allowed."
36
+ And I should not see the error message "The Email Address field must contain a unique value."
@@ -0,0 +1,42 @@
1
+ @framework-pages
2
+ Feature: The pages of the framework
3
+ As the owner of a live app
4
+ I want the framework's own pages to answer as a live app's should
5
+ So that visitors see a plain page, and nobody learns how the app is built
6
+
7
+ # The browser logs every error page as a resource that failed to load: the scenarios that open
8
+ # one carry @js-off.
9
+
10
+ @critical
11
+ Scenario: A new app shows its welcome page at its home address, in production
12
+ Given I am an anonymous user
13
+ When I go to the homepage
14
+ Then the response status code should be 200
15
+ And I should see the welcome page
16
+ And I should see "The small framework with powerful features"
17
+ And the page should say it runs in the "production" environment
18
+ And I should not see the debug toolbar
19
+
20
+ Scenario: The pages of a live app carry no debug toolbar
21
+ Given I am a logged in user with the "user" user
22
+ When I go to "/account"
23
+ Then I should not see the debug toolbar
24
+ When I go to "/login"
25
+ Then I should not see the debug toolbar
26
+
27
+ @critical @js-off
28
+ Scenario: An address the app does not have answers with the 404 page
29
+ Given I am an anonymous user
30
+ When I go to "/no-such-page-of-the-app"
31
+ Then I should see the 404 error page
32
+ And the response status code should be 404
33
+ And I should see "Sorry! Cannot seem to find the page you were looking for."
34
+ And the page should not show debug information
35
+
36
+ @critical @js-off
37
+ Scenario: An error nothing catches shows the 500 page and no debug information
38
+ Given I am an anonymous user
39
+ When I go to "/test-fixtures/server-error"
40
+ Then I should see the 500 error page
41
+ And the page should not show debug information
42
+ And I should not see "The test app raised this error on purpose."
@@ -0,0 +1,43 @@
1
+ @login-link
2
+ Feature: The login link by mail
3
+ As an account of the app that lost its password
4
+ I want a link by mail that logs me in
5
+ So that I get into my account without the password, once
6
+
7
+ # The mail is read from the mail catcher of the test app (worldParameters.mailUrl).
8
+
9
+ @critical
10
+ Scenario: The link the app mails logs the account in
11
+ Given I am an anonymous user
12
+ When I ask for a login link for "user"
13
+ Then I should see "Check your email!"
14
+ And I should see "We just sent you an email with a Login link inside. It is only valid for 60 minutes."
15
+ And an email with the subject "Your Login Link" should be sent to "user"
16
+ And the email with the subject "Your Login Link" to "user" should contain "Username: user"
17
+ When I open the "Login" link of the email to "user"
18
+ Then I should be logged in as "user"
19
+
20
+ Scenario: A link that was used is refused the second time
21
+ Given I am an anonymous user
22
+ When I ask for a login link for "developer"
23
+ And I open the "Login" link of the email to "developer"
24
+ Then I should be logged in as "developer"
25
+ When I log out
26
+ And I open the "Login" link of the email to "developer"
27
+ Then I should be on "/login/magic-link"
28
+ And I should see the error message "Unable to verify the link."
29
+ And I should not be logged in
30
+
31
+ Scenario: An address with no account gets no link
32
+ Given I am an anonymous user
33
+ When I ask for a login link for "nobody@example.com"
34
+ Then I should see the error message "Unable to verify the email address"
35
+ And no email should be sent to "nobody@example.com"
36
+
37
+ Scenario: The page that sends a login link goes back to the login form
38
+ Given I am an anonymous user
39
+ When I go to "/login"
40
+ And I click "Use a Login Link"
41
+ Then I should be on "/login/magic-link"
42
+ When I click "Back to Login"
43
+ Then I should see the login form
@@ -0,0 +1,65 @@
1
+ @registration
2
+ Feature: Registration, through its refusals
3
+ As the owner of the app
4
+ I want the registration form to refuse what it must
5
+ So that no account is made with a taken address or name, or a weak password
6
+
7
+ # A suite never makes an account: every scenario sends the address of an account the app already
8
+ # has, so even a form the app took by mistake would make nothing.
9
+
10
+ Background:
11
+ Given I am an anonymous user
12
+ And I am on "/register"
13
+
14
+ @critical
15
+ Scenario: An address that is taken is refused
16
+ When I fill in "Email Address" with the email of "user"
17
+ And I fill in "Username" with "new.person"
18
+ And I fill in "Password" with "Strong-Pass-2026!"
19
+ And I fill in "Password (again)" with "Strong-Pass-2026!"
20
+ And I click the "Register" button
21
+ Then I should be on "/register"
22
+ And I should see the error message "The Email Address field must contain a unique value."
23
+ And the "Email Address" field should hold the email of "user"
24
+ And I should not be logged in
25
+
26
+ Scenario: A user name that is taken is refused
27
+ When I fill in "Email Address" with the email of "admin"
28
+ And I fill in "Username" with the username of "user"
29
+ And I fill in "Password" with "Strong-Pass-2026!"
30
+ And I fill in "Password (again)" with "Strong-Pass-2026!"
31
+ And I click the "Register" button
32
+ Then I should see the error message "The Username field must contain a unique value."
33
+ And the "Username" field should hold the username of "user"
34
+
35
+ Scenario: A confirmation that differs from the password is refused
36
+ When I fill in "Email Address" with the email of "user"
37
+ And I fill in "Username" with "new.person"
38
+ And I fill in "Password" with "Strong-Pass-2026!"
39
+ And I fill in "Password (again)" with "Other-Pass-2026!"
40
+ And I click the "Register" button
41
+ Then I should see the error message "The Password (again) field does not match the Password field."
42
+
43
+ Scenario: A password that is too short is refused
44
+ When I fill in "Email Address" with the email of "user"
45
+ And I fill in "Username" with "new.person"
46
+ And I fill in "Password" with "abc"
47
+ And I fill in "Password (again)" with "abc"
48
+ And I click the "Register" button
49
+ Then I should see the error message "Passwords must be at least 8 characters long."
50
+
51
+ Scenario: A common password is refused
52
+ When I fill in "Email Address" with the email of "user"
53
+ And I fill in "Username" with "new.person"
54
+ And I fill in "Password" with "password123"
55
+ And I fill in "Password (again)" with "password123"
56
+ And I click the "Register" button
57
+ Then I should see the error message "Password must not be a common password."
58
+
59
+ Scenario: An empty user name is refused by the browser before anything is sent
60
+ When I fill in "Email Address" with the email of "user"
61
+ And I fill in "Password" with "Strong-Pass-2026!"
62
+ And I fill in "Password (again)" with "Strong-Pass-2026!"
63
+ And I click the "Register" button
64
+ Then the "Username" field should block submission as required
65
+ And I should not see any error message
@@ -0,0 +1,104 @@
1
+ @session
2
+ Feature: The session
3
+ As an account of the app
4
+ I want to log in, stay logged in, and log out
5
+ So that only I use my account, and only while I mean to
6
+
7
+ @critical
8
+ Scenario: An account logs in with the login form and lands on the home page
9
+ Given I am an anonymous user
10
+ When I log in as "user" with the login form
11
+ Then I should be on the homepage
12
+ And I should see the welcome page
13
+ And I should be logged in as "user"
14
+
15
+ Scenario: A wrong password is refused with the error message of the login page
16
+ Given I am an anonymous user
17
+ When I log in with the email "user@example.com" and the password "wrong-password"
18
+ Then I should see the login form
19
+ And I should see the error message "Unable to log you in. Please check your password."
20
+ And the "Email Address" field should hold the email of "user"
21
+ And I should not be logged in
22
+
23
+ Scenario: An address with no account is refused
24
+ Given I am an anonymous user
25
+ When I log in with the email "nobody@example.com" and the password "wrong-password"
26
+ Then I should see the error message "Unable to log you in. Please check your credentials."
27
+ And I should not be logged in
28
+
29
+ Scenario: An address the browser takes but the app does not is refused by the app
30
+ Given I am an anonymous user
31
+ When I log in with the email "a@b" and the password "wrong-password"
32
+ Then I should see the error message "The Email Address field must contain a valid email address."
33
+ And I should not see the error message "Unable to log you in. Please check your credentials."
34
+
35
+ Scenario: A banned account is refused
36
+ Given I am an anonymous user
37
+ When I go to "/login"
38
+ And I fill in "Email Address" with the email of "banned"
39
+ And I fill in "Password" with the password of "banned"
40
+ And I click the "Login" button
41
+ Then I should see the error message "Can not log you in as you are currently banned."
42
+ And I should not be logged in
43
+
44
+ Scenario: An empty password is refused by the browser before anything is sent
45
+ Given I am an anonymous user
46
+ When I go to "/login"
47
+ And I fill in "Email Address" with the email of "user"
48
+ And I click the "Login" button
49
+ Then the "Password" field should block submission as required
50
+ And I should be on "/login"
51
+
52
+ @critical
53
+ Scenario: A page that needs a session sends a visitor to the login form, and the login back to it
54
+ Given I am an anonymous user
55
+ When I go to "/account"
56
+ Then I should see the login form
57
+ When I fill in "Email Address" with the email of "user"
58
+ And I fill in "Password" with the password of "user"
59
+ And I click the "Login" button
60
+ Then I should be on "/account"
61
+ And I should see "Signed in as user"
62
+
63
+ Scenario: The session holds through a reload and a page of the app
64
+ Given I am a logged in user with the "developer" user
65
+ When I go to "/account"
66
+ And I reload the page
67
+ Then I should see "Signed in as developer"
68
+ And I should be logged in as "developer"
69
+
70
+ Scenario: The login page sends an account that is logged in on to the home page
71
+ Given I am a logged in user with the "user" user
72
+ When I go to "/login"
73
+ Then I should not see the login form
74
+ And I should be on the homepage
75
+
76
+ @critical
77
+ Scenario: Logging out ends the session and says so
78
+ Given I am an anonymous user
79
+ When I log in as "user" with the login form
80
+ And I go to "/account"
81
+ And I log out
82
+ Then I should see the login form
83
+ And I should see the success message "You have successfully logged out."
84
+ And I should not be logged in
85
+
86
+ # Logging out leaves the "remember" cookie in the browser, but the app forgets its token: it logs
87
+ # nobody in any more.
88
+ Scenario: A remembered login outlives the session, and logging out ends it for good
89
+ Given I am an anonymous user
90
+ When I log in as "user" with the login form and ask to be remembered
91
+ Then a cookie with the name "remember" should exist
92
+ When my session expires
93
+ Then I should be logged in
94
+ And I should be logged in as "user"
95
+ When I log out
96
+ And my session expires
97
+ Then I should not be logged in
98
+
99
+ Scenario: A login that was not remembered ends with the session
100
+ Given I am an anonymous user
101
+ When I log in as "user" with the login form
102
+ Then a cookie with the name "remember" should not exist
103
+ When my session expires
104
+ Then I should not be logged in
@@ -0,0 +1,37 @@
1
+ # Step definitions
2
+
3
+ | File | Covers |
4
+ | --- | --- |
5
+ | `codeigniter-session.steps.js` | The session: login by a handle of the users registry (a session taken over when the account already has one), login through the form (remembered or not), login with an address and a password, logout, who is signed in, the login form, a session that expires, the login link asked for by mail. |
6
+ | `codeigniter-mail.steps.js` | The mail the app sends: that it arrived (or none did), what it says, a link of it opened as a person does. |
7
+ | `codeigniter-forms.steps.js` | Forms as a person reads them: a field filled with the address, user name or password of an account of the registry, a field that holds them, the error, success, warning and information messages of a page, a field the browser refuses as empty, a form whose security token is out of date. |
8
+ | `codeigniter-access.steps.js` | Groups and permissions: a page an account may open or not, and a table of who may open a page. |
9
+ | `codeigniter-pages.steps.js` | The framework's own pages: the welcome page and the environment it says, the error page of a status, the debug information a live app must not show, a login form sent from another site. |
10
+ | `codeigniter-toolbar.steps.js` | The debug toolbar of an app in development: that a page has it (or not), a panel opened, what a panel shows. |
11
+ | `codeigniter-helpers.js` | Shared plumbing: the wait budget, the answers on the way to a page, friendly errors, the paths of the app, the users registry, the session cache and the login, fields, the messages of a page, the mailbox of the test app, the status of the page. It registers no step. |
12
+
13
+ ## Rules for a new step
14
+
15
+ - Check `node_modules/webship-js/tests/step-definitions/` first: a step that the
16
+ generic click, fill and see vocabulary already covers is not added here.
17
+ - No step phrase names the framework or a library. A name appears only as an
18
+ argument a step asserts.
19
+ - The regular expression starts with the pronoun group `(I |we )*` where a
20
+ person acts, and an assertion takes `should( not)*`, so one definition reads
21
+ both polarities.
22
+ - A JSDoc block above the step holds at least five `Example #N:` lines. Run
23
+ `npm run test:examples`: every example must match its own step and no step of
24
+ webship-js.
25
+ - Find things the way a person does: a label, a role, a text. The stable hooks
26
+ of the pages (`role="alert"`, the contextual classes of a message, the name of
27
+ a field, the ids of the debug toolbar) are the fallback.
28
+ - Wait on the page, never on a fixed time: on the locator, on the navigation a
29
+ form or a link starts, on the requests of the page (`settle`).
30
+ - Fail with `friendly({ message, hint })`: what was expected, what was found
31
+ and where to look.
32
+ - A step never creates or deletes a user: accounts are configuration, named in
33
+ the `users` registry of `cucumber.js` and created by the build of the app.
34
+ - Open the page in a real browser before writing or changing its step, and
35
+ write the step from what is there: the roles and names of the accessibility
36
+ tree, the stable attributes, what the page does while it loads or saves.
37
+ - Give every assertion a scenario in `tests/must-fail/` that makes it fail.
@@ -0,0 +1,122 @@
1
+ 'use strict';
2
+
3
+ // Groups and permissions, as a person meets them: a page an account may open,
4
+ // and a page the app turns it away from. The app guards a page with the
5
+ // filters of its auth library (a group, a permission, or a session); what the
6
+ // browser sees is the outcome: the page itself, the login form for a visitor,
7
+ // or a refusal (a redirect away from the page, or HTTP 401 or 403).
8
+
9
+ const { Then } = require('@cucumber/cucumber');
10
+ const { friendly } = require('webship-js/tests/step-definitions/webship');
11
+ const {
12
+ clean,
13
+ siteUrl,
14
+ loginPath,
15
+ pathOf,
16
+ open,
17
+ documentStatus,
18
+ loginForm,
19
+ logInAs,
20
+ } = require('./codeigniter-helpers');
21
+
22
+ /**
23
+ * Open a page and say what the app did with it: "allowed" (the page itself),
24
+ * "login" (a visitor sent to the login form), "denied" (sent elsewhere, or
25
+ * answered with HTTP 401 or 403), or "error" (any other error status).
26
+ *
27
+ * @returns {Promise<{access: string, path: string, status: (number|null), where: string, how: string}>}
28
+ */
29
+ async function access(world, path) {
30
+ const answers = await open(world, siteUrl(world, path));
31
+ const asked = pathOf(siteUrl(world, path));
32
+ const where = pathOf(world.page.url());
33
+ const status = await documentStatus(world);
34
+ const first = answers[0];
35
+ const how = first && first.status >= 300 && first.status < 400
36
+ ? `a redirect (HTTP ${first.status}) to ${pathOf(first.location || world.page.url())}`
37
+ : `HTTP ${status === null ? '(unknown)' : status}`;
38
+ let result;
39
+ if (where !== asked && (where === pathOf(loginPath(world)) || (await loginForm(world).isVisible().catch(() => false)))) result = 'login';
40
+ else if (where !== asked || status === 401 || status === 403) result = 'denied';
41
+ else if (status && status >= 400) result = 'error';
42
+ else result = 'allowed';
43
+ return { access: result, path: asked, status, where, how };
44
+ }
45
+
46
+ /** What an outcome reads like in a failure message. */
47
+ function told(outcome) {
48
+ switch (outcome.access) {
49
+ case 'allowed': return `it opened the page (${outcome.how})`;
50
+ case 'login': return `it sent the browser to the login form (${outcome.how})`;
51
+ case 'denied': return outcome.where !== outcome.path ? `it turned the browser away to ${outcome.where} (${outcome.how})` : `it refused the page (${outcome.how})`;
52
+ default: return `the page answered ${outcome.how}`;
53
+ }
54
+ }
55
+
56
+ /**
57
+ * Open a page and assert that the account in the browser may, or may not,
58
+ * open it. Allowed: the browser stays on the page and it answers without an
59
+ * error. Not allowed: the app sends the browser elsewhere (the login form for
60
+ * a visitor, another page for an account without the group or the
61
+ * permission) or answers HTTP 401 or 403.
62
+ *
63
+ * Example #1: Then I should have access to "/admin"
64
+ * Example #2: Then I should not have access to "/admin"
65
+ * Example #3: And we should have access to "/settings"
66
+ * Example #4: Then I should not have access to "/settings"
67
+ * Example #5: But we should not have access to "/account"
68
+ */
69
+ Then(/^(I |we )*should( not)* have access to "([^"]*)"$/, async function (pronounCase, notCase, path) {
70
+ const outcome = await access(this, path);
71
+ if (notCase && outcome.access === 'allowed') {
72
+ throw friendly({ message: `Expected no access to ${outcome.path}, but ${told(outcome)}.`, hint: 'The app guards a page with a filter of its auth library (a group, a permission, or a session): check the filter of the route and the groups of the account.' });
73
+ }
74
+ if (!notCase && outcome.access !== 'allowed') {
75
+ throw friendly({ message: `Expected access to ${outcome.path}, but ${told(outcome)}.`, hint: 'Log in as an account of a group the page lets in (I am a logged in user with the "..." user).' });
76
+ }
77
+ if (notCase && outcome.access === 'error') {
78
+ throw friendly({ message: `Expected the app to turn the browser away from ${outcome.path}, but ${told(outcome)}: that is an error, not a refusal.`, hint: 'Check the address: a refusal is a redirect, or HTTP 401 or 403.' });
79
+ }
80
+ });
81
+
82
+ const ACCESS = { allowed: 'allowed', denied: 'denied', login: 'login', 'login form': 'login' };
83
+
84
+ /**
85
+ * Assert who may open a page, row by row: an account of the users registry
86
+ * (by its handle), or "visitor" for a browser that is signed in as nobody,
87
+ * and what the app does with it: "allowed" (the page opens), "denied" (the
88
+ * app turns the account away, or answers HTTP 401 or 403) or "login" (a
89
+ * visitor is sent to the login form). Every row is checked, and the failure
90
+ * lists every row that differs.
91
+ *
92
+ * Example #1: Then the access to "/admin" should be:
93
+ * Example #2: Then the access to "/settings" should be:
94
+ * Example #3: And the access to "/account" should be:
95
+ * Example #4: Then the access to "/admin" should be:
96
+ * Example #5: And the access to "/settings" should be:
97
+ */
98
+ Then(/^the access to "([^"]*)" should be:$/, { timeout: 300000 }, async function (path, table) {
99
+ const rows = table.hashes();
100
+ if (!rows.length || !('account' in rows[0]) || !('access' in rows[0])) {
101
+ throw friendly({ message: 'The table needs the columns "account" and "access", and a row per account.', hint: '| account | access | then rows such as | admin | allowed |, | user | denied |, | visitor | login |.' });
102
+ }
103
+ const wrong = [];
104
+ for (const row of rows) {
105
+ const account = clean(row.account);
106
+ const wanted = ACCESS[clean(row.access).toLowerCase()];
107
+ if (!wanted) {
108
+ throw friendly({ message: `"${row.access}" is not an access the table knows (row "${account}").`, hint: 'Use "allowed", "denied" or "login".' });
109
+ }
110
+ if (account === 'visitor') {
111
+ await this.page.context().clearCookies();
112
+ } else {
113
+ await logInAs(this, account);
114
+ }
115
+ const outcome = await access(this, path);
116
+ if (outcome.access !== wanted) wrong.push(`"${account}": expected ${wanted}, but ${told(outcome)}`);
117
+ }
118
+ await this.page.context().clearCookies();
119
+ if (wrong.length) {
120
+ throw friendly({ message: `The access to ${pathOf(siteUrl(this, path))} differs for ${wrong.length} of ${rows.length} rows: ${wrong.join('; ')}.`, hint: 'The app guards a page with a filter of its auth library: check the filter of the route and the groups and permissions of each account.' });
121
+ }
122
+ });