forked from mtusi2026/mtusi2026lab2
feat: lab2 done
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
meta {
|
||||
name: Basic on business endpoint
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{baseUrl}}/api/v1/users/me
|
||||
body: none
|
||||
auth: basic
|
||||
}
|
||||
|
||||
auth:basic {
|
||||
username: {{username}}
|
||||
password: {{password}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Basic принимается только на POST /auth/sessions. На бизнес-endpoint
|
||||
он даёт 401 с Bearer-challenge, даже если credentials верные.
|
||||
}
|
||||
|
||||
tests {
|
||||
test("401 unauthorized", function() {
|
||||
expect(res.status).to.equal(401);
|
||||
});
|
||||
|
||||
test("Bearer challenge", function() {
|
||||
expect(res.headers["www-authenticate"]).to.equal('Bearer realm="messenger"');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
meta {
|
||||
name: Blank message and extra field
|
||||
type: http
|
||||
seq: 7
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{baseUrl}}/api/v1/chats/{{chatId}}/messages
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
Authorization: Bearer {{token}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Пробельный текст запрещён, а поле sender_id не принимается:
|
||||
strict validation отвечает 400 (лишние поля отклоняются, а не игнорируются).
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"text": " ",
|
||||
"sender_id": "{{secondUserId}}"
|
||||
}
|
||||
}
|
||||
|
||||
tests {
|
||||
test("400 invalid_request", function() {
|
||||
expect(res.status).to.equal(400);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
meta {
|
||||
name: Duplicate username returns 409
|
||||
type: http
|
||||
seq: 8
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{baseUrl}}/api/v1/users
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
docs {
|
||||
Повторная регистрация того же username. Уникальность обеспечивает
|
||||
unique-индекс PostgreSQL, ошибка 23505 маппится в 409 (не 500).
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"username": "{{username}}",
|
||||
"display_name": "Дубликат",
|
||||
"password": "{{password}}"
|
||||
}
|
||||
}
|
||||
|
||||
tests {
|
||||
test("409 conflict", function() {
|
||||
expect(res.status).to.equal(409);
|
||||
});
|
||||
|
||||
test("код ошибки conflict", function() {
|
||||
expect(res.body.error.code).to.equal("conflict");
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
meta {
|
||||
name: Invalid limit and cursor
|
||||
type: http
|
||||
seq: 6
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{baseUrl}}/api/v1/chats/{{chatId}}/messages?limit=101&cursor=not-a-cursor
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
Authorization: Bearer {{token}}
|
||||
}
|
||||
|
||||
docs {
|
||||
limit вне 1..100 и неизвестный cursor — 400 invalid_request,
|
||||
в одном формате ошибки с request_id, совпадающим с заголовком.
|
||||
}
|
||||
|
||||
tests {
|
||||
test("400 invalid_request", function() {
|
||||
expect(res.status).to.equal(400);
|
||||
});
|
||||
|
||||
test("формат ошибки по контракту", function() {
|
||||
expect(res.body.error.code).to.equal("invalid_request");
|
||||
expect(res.body.error.request_id).to.equal(res.headers["x-request-id"]);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
meta {
|
||||
name: Non-member receives 404
|
||||
type: http
|
||||
seq: 5
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{baseUrl}}/api/v1/chats/{{chatId}}
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
Authorization: Bearer {{thirdToken}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Аутентификация прошла, но доступа к ресурсу нет. Контракт требует 404,
|
||||
а не 403: существование чужого чата не раскрывается.
|
||||
}
|
||||
|
||||
tests {
|
||||
test("404 not_found", function() {
|
||||
expect(res.status).to.equal(404);
|
||||
});
|
||||
|
||||
test("код ошибки not_found", function() {
|
||||
expect(res.body.error.code).to.equal("not_found");
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
meta {
|
||||
name: Wrong password
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{baseUrl}}/api/v1/auth/sessions
|
||||
body: none
|
||||
auth: basic
|
||||
}
|
||||
|
||||
auth:basic {
|
||||
username: {{username}}
|
||||
password: definitely-wrong-password
|
||||
}
|
||||
|
||||
docs {
|
||||
Неверный пароль: 401 без раскрытия, существует ли пользователь,
|
||||
и с тем же Basic-challenge, что и при неизвестном пользователе.
|
||||
}
|
||||
|
||||
tests {
|
||||
test("401 unauthorized", function() {
|
||||
expect(res.status).to.equal(401);
|
||||
});
|
||||
|
||||
test("Basic challenge", function() {
|
||||
expect(res.headers["www-authenticate"]).to.equal('Basic realm="messenger", charset="UTF-8"');
|
||||
});
|
||||
|
||||
test("request_id совпадает с заголовком", function() {
|
||||
expect(res.body.error.request_id).to.equal(res.headers["x-request-id"]);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
meta {
|
||||
name: X-User-Id alone does not authenticate
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{baseUrl}}/api/v1/users/me
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
X-User-Id: {{userId}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Заголовок X-User-Id остался от lab1 и с lab2 не даёт доступа:
|
||||
без действующей Bearer-сессии ответ 401.
|
||||
}
|
||||
|
||||
tests {
|
||||
test("401 unauthorized", function() {
|
||||
expect(res.status).to.equal(401);
|
||||
});
|
||||
|
||||
test("Bearer challenge", function() {
|
||||
expect(res.headers["www-authenticate"]).to.equal('Bearer realm="messenger"');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
meta {
|
||||
name: X-User-Id cannot spoof the session owner
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{baseUrl}}/api/v1/users/me
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
Authorization: Bearer {{token}}
|
||||
X-User-Id: {{secondUserId}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Владелец запроса определяется только токеном: X-User-Id с ID другого
|
||||
пользователя игнорируется, ответ содержит владельца сессии.
|
||||
}
|
||||
|
||||
tests {
|
||||
test("200 ok", function() {
|
||||
expect(res.status).to.equal(200);
|
||||
});
|
||||
|
||||
test("вернулся владелец сессии, а не подставленный ID", function() {
|
||||
expect(res.body.id).to.equal(bru.getVar("userId"));
|
||||
expect(res.body.id).to.not.equal(bru.getVar("secondUserId"));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user