Skip to content

Commit 797eada

Browse files
committed
add test and docs for 401 Unauthorized
1 parent c631ecd commit 797eada

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

docs/api/v1.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ All defined routes in the specification are appended to this url. To access all
6565
}, // etc
6666
]
6767
```
68+
69+
##### 401 Unauthorized
70+
No valid authentication credentials supplied.
6871
</details>
6972

7073

@@ -92,6 +95,9 @@ All defined routes in the specification are appended to this url. To access all
9295
##### 400 Bad Request
9396
Invalid ID supplied.
9497

98+
##### 401 Unauthorized
99+
No valid authentication credentials supplied.
100+
95101
##### 404 Not Found
96102
Note not found.
97103
</details>
@@ -117,6 +123,9 @@ Note not found.
117123
##### 400 Bad Request
118124
Invalid ID supplied.
119125

126+
##### 401 Unauthorized
127+
No valid authentication credentials supplied.
128+
120129
##### 507 Insufficient Storage
121130
Not enough free storage for saving the note's content.
122131
</details>
@@ -138,6 +147,9 @@ Not enough free storage for saving the note's content.
138147
##### 400 Bad Request
139148
Invalid ID supplied.
140149

150+
##### 401 Unauthorized
151+
No valid authentication credentials supplied.
152+
141153
##### 404 Not Found
142154
Note not found.
143155

@@ -161,6 +173,9 @@ Note is deleted.
161173
##### 400 Bad Request
162174
Invalid ID supplied.
163175

176+
##### 401 Unauthorized
177+
No valid authentication credentials supplied.
178+
164179
##### 404 Not Found
165180
Note not found.
166181
</details>

tests/api/AbstractAPITest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,17 @@ protected function checkResponse(
4646
$response->getHeaderLine('Content-Type'),
4747
$message.': Response content type'
4848
);
49-
$this->assertTrue(
50-
$response->hasHeader('X-Notes-API-Versions'),
51-
$message.': Response has Notes-API-Versions header'
52-
);
53-
$this->assertContains(
54-
$this->apiVersion,
55-
explode(', ', $response->getHeaderLine('X-Notes-API-Versions')),
56-
$message.': Response Notes-API-Versions header'
57-
);
49+
if ($statusExp !== 401) {
50+
$this->assertTrue(
51+
$response->hasHeader('X-Notes-API-Versions'),
52+
$message.': Response has Notes-API-Versions header'
53+
);
54+
$this->assertContains(
55+
$this->apiVersion,
56+
explode(', ', $response->getHeaderLine('X-Notes-API-Versions')),
57+
$message.': Response Notes-API-Versions header'
58+
);
59+
}
5860
}
5961

6062
protected function checkGetReferenceNotes(

tests/api/CommonAPITest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,5 +238,9 @@ public function testInsuficientStorage() {
238238
$this->assertEquals(507, $response2->getStatusCode());
239239
}
240240

241-
// TODO Test settings (switch to another notes folder)
241+
public function testUnauthorized() {
242+
$auth = ['test', 'wrongpassword'];
243+
$response = $this->http->request('GET', 'notes', [ 'auth' => $auth ]);
244+
$this->checkResponse($response, 'Get existing notes', 401);
245+
}
242246
}

0 commit comments

Comments
 (0)