You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+28-30Lines changed: 28 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,17 +34,17 @@ npm install
34
34
35
35
## Limitations
36
36
37
-
Additional security mechanisms like **CSRF tokens**, **rate limiting**, or **IP blocking** should be disabled during testing. Otherwise, they may interfere with the testing process. Temporarily disable such protections via environment variables or similar mechanisms to ensure accurate test results.
37
+
Additional security mechanisms like **CSRF tokens**, **rate limiting**, or **IP blocking** should be disabled during testing. Otherwise, they may interfere with the testing process. For example, a `403 Forbidden` status code caused by IP blocking might be misinterpreted by the tool. Temporarily disable such protections via environment variables or similar mechanisms to ensure accurate test results.
38
38
39
39
Currently, only one resource per operation can be defined. The tool does not support multiple resources in a single route (e.g., `/groups/:groupId/members/:memberId`). Simple routes like `/members/:memberId` are fully supported.
40
40
41
-
Also, the tool only supports APIs that communicate via JSON. XML or other data formats are not yet supported.
41
+
Also, the tool only supports APIs communicating via JSON. XML or other formats are not yet supported.
42
42
43
43
---
44
44
45
45
## Assumptions
46
46
47
-
The tool assumes that tested web applications follow this sequence when handling requests:
47
+
The tool assumes tested web applications follow this sequence when handling requests:
48
48
49
49
1. User identity verification (*Authentication*)
50
50
2. User permission verification (*Authorization*)
@@ -71,13 +71,13 @@ First, determine clearly which API routes represent resources and the type of ac
71
71
72
72
The following custom annotations (prefixed with `x-act-`) are required to specify resources and access types:
73
73
74
-
-`x-act-resource-name`: Indicates the resource accessed by the operation.
75
-
-`x-act-resource-access`: Specifies the access type (`create`, `read`, `update`, `delete`).
74
+
-`x-act-resource-name`: Indicates the resource accessed.
75
+
-`x-act-resource-access`: Specifies access type.
76
76
77
-
Annotations can be provided inline or nested:
77
+
Annotations can be inline or nested under `x-act`:
78
78
79
79
<detailsopen>
80
-
<summary>Example of Inline Annotation</summary>
80
+
<summary><strong>Example of Inline Annotation</strong></summary>
81
81
82
82
```yaml
83
83
x-act-resource-name: Todo
@@ -86,7 +86,7 @@ x-act-resource-access: read
86
86
</details>
87
87
88
88
<details open>
89
-
<summary>Example of Nested Annotation</summary>
89
+
<summary><strong>Example of Nested Annotation</strong></summary>
90
90
91
91
```yaml
92
92
x-act:
@@ -96,20 +96,20 @@ x-act:
96
96
</details>
97
97
98
98
<details>
99
-
<summary>Full Example of Resource Annotations</summary>
99
+
<summary><strong>Complete Example of OpenAPI Annotations</strong></summary>
100
100
101
101
```yaml
102
102
paths:
103
103
/todos:
104
104
get:
105
105
# ...
106
106
x-act:
107
-
resource-name: User
107
+
resource-name: Todo
108
108
resource-access: read
109
109
post:
110
110
# ...
111
111
x-act:
112
-
resource-name: User
112
+
resource-name: Todo
113
113
resource-access: create
114
114
115
115
/todos/{id}:
@@ -122,33 +122,31 @@ paths:
122
122
schema:
123
123
type: string
124
124
x-act:
125
-
resource-name: User
125
+
resource-name: Todo
126
126
resource-access: read
127
127
```
128
128
</details>
129
129
130
-
Additionally, define security schemes in your OpenAPI file, either globally or at the individual operation level. For more details, refer to the [Security Scheme documentation](https://swagger.io/docs/specification/authentication/).
131
-
132
130
---
133
131
134
132
### 3. Annotating Authentication Endpoints
135
133
136
-
Ensure you have a valid security scheme defined. Refer to the [Security Scheme documentation](https://learn.openapis.org/specification/security.html).
134
+
Before annotating authentication endpoints, ensure a valid security scheme is defined in your OpenAPI specification. See the [Security Scheme documentation](https://learn.openapis.org/specification/security.html).
137
135
138
-
To automate authentication, use these annotations:
136
+
Use these annotations to allow the tool to authenticate automatically:
139
137
140
-
- `x-act-auth-endpoint`: Matches your security scheme key.
138
+
- `x-act-auth-endpoint`: Must match your defined security scheme key and must be provided on operation-level.
141
139
- `x-act-auth-field`:
142
-
- `identifier`: Username/email.
143
-
- `password`: Password.
144
-
- `token`: Token field in response.
140
+
- `identifier`: Username/email (request body)
141
+
- `password`: Password (request body)
142
+
- `token`: Token returned (response body)
145
143
146
144
> [!IMPORTANT]
147
145
> For bearer authentication, the token field must be at the top level of the response. Nested fields like `{ data: { token: "<token>" } }` are currently not supported.
148
146
149
147
150
148
<details>
151
-
<summary>Example of an annotated Bearer token endpoint</summary>
149
+
<summary><strong>Example of an Authentication Endpoint (Bearer)</strong></summary>
152
150
153
151
```yaml
154
152
paths:
@@ -188,16 +186,16 @@ paths:
188
186
189
187
### 4. Defining Users and Resources
190
188
191
-
Define users and resources clearly, ensuring names match exactly (case-sensitive) those in the OpenAPI annotations.
189
+
Define user-resource relationships explicitly. Resource names must match exactly (case-sensitive) the values used in the OpenAPI annotations (`x-act-resource-name`):
192
190
193
191
<details open>
194
-
<summary>Example of User-Resource Definition</summary>
192
+
<summary><strong>Example of User-Resource Definition</strong></summary>
195
193
196
194
```typescript
197
195
import { User, Resource } from 'access-control-testing'
198
196
199
197
const user1 = new User('myusername', 'mysecretpassword')
200
-
const todoResource = new Resource('Todo') // Matches 'Todo' exactly
198
+
const todoResource = new Resource('Todo') // Name must exactly match OpenAPI spec annotation
201
199
202
200
user1.canView(todoResource, 123) // user1 can view Todo instance with identifier 123
203
201
user1.canEdit(todoResource, 123) // user1 can edit Todo instance with identifier 123
@@ -213,13 +211,13 @@ user1.owns(todoResource) // user1 owns created Todo instances
213
211
214
212
Provide the following properties when configuring the tool:
215
213
216
-
- `apiBaseUrl`: Base URL of the API under test.
217
-
- `openApiUrl`: URL to your annotated OpenAPI spec.
218
-
- `users`: Array of user objects.
219
-
- `resources`: Array of resource objects.
214
+
- `apiBaseUrl`: The base URL where your API is accessible.
215
+
- `openApiUrl`: URL pointing to your annotated OpenAPI spec.
216
+
- `users`: Array of defined users.
217
+
- `resources`: Array of defined resources.
220
218
221
219
<details open>
222
-
<summary>Example of Tool Configuration</summary>
220
+
<summary><strong>Example of Tool Configuration</strong></summary>
223
221
224
222
```typescript
225
223
const users = [user1]
@@ -241,7 +239,7 @@ const act = new Act({
241
239
After setup, tests are generated and executed as follows:
242
240
243
241
<details open>
244
-
<summary>Example of Running Tests</summary>
242
+
<summary><strong>Example of Running Tests</strong></summary>
245
243
246
244
```typescript
247
245
import { Act, NodeTestRunner } from 'access-control-testing'
0 commit comments