forked from mtusi2026/mtusi2026lab2
feat: lab2 done
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
meta {
|
||||
name: Create second session (Basic)
|
||||
type: http
|
||||
seq: 5
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{baseUrl}}/api/v1/auth/sessions
|
||||
body: none
|
||||
auth: basic
|
||||
}
|
||||
|
||||
auth:basic {
|
||||
username: {{secondUsername}}
|
||||
password: {{password}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Сессия второго участника чата: нужна, чтобы читать историю другой
|
||||
действующей сессией (read-after-write). Сохраняет secondToken.
|
||||
}
|
||||
|
||||
tests {
|
||||
test("201 created", function() {
|
||||
expect(res.status).to.equal(201);
|
||||
});
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setVar("secondToken", res.body.token);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
meta {
|
||||
name: Create third session (Basic)
|
||||
type: http
|
||||
seq: 6
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{baseUrl}}/api/v1/auth/sessions
|
||||
body: none
|
||||
auth: basic
|
||||
}
|
||||
|
||||
auth:basic {
|
||||
username: {{thirdUsername}}
|
||||
password: {{password}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Сессия постороннего пользователя: используется только в негативных
|
||||
проверках доступа к чужому чату. Сохраняет thirdToken.
|
||||
}
|
||||
|
||||
tests {
|
||||
test("201 created", function() {
|
||||
expect(res.status).to.equal(201);
|
||||
});
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setVar("thirdToken", res.body.token);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
meta {
|
||||
name: Create session (Basic)
|
||||
type: http
|
||||
seq: 4
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{baseUrl}}/api/v1/auth/sessions
|
||||
body: none
|
||||
auth: basic
|
||||
}
|
||||
|
||||
auth:basic {
|
||||
username: {{username}}
|
||||
password: {{password}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Вход: Authorization: Basic base64(username:password), тело запроса не передаётся.
|
||||
Пароль кодируется как UTF-8, разделитель — первый символ ":".
|
||||
Сохраняет token и expiresAt. Неверные credentials дают 401 с
|
||||
WWW-Authenticate: Basic realm="messenger", charset="UTF-8".
|
||||
}
|
||||
|
||||
tests {
|
||||
test("201 created", function() {
|
||||
expect(res.status).to.equal(201);
|
||||
});
|
||||
|
||||
test("token_type bearer", function() {
|
||||
expect(res.body.token_type).to.equal("Bearer");
|
||||
});
|
||||
|
||||
test("expires_at в UTC", function() {
|
||||
expect(res.body.expires_at).to.match(/Z$/);
|
||||
});
|
||||
|
||||
test("user совпадает с зарегистрированным", function() {
|
||||
expect(res.body.user.id).to.equal(bru.getVar("userId"));
|
||||
});
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setVar("token", res.body.token);
|
||||
bru.setVar("expiresAt", res.body.expires_at);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
meta {
|
||||
name: Current user
|
||||
type: http
|
||||
seq: 7
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{baseUrl}}/api/v1/users/me
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
headers {
|
||||
Authorization: Bearer {{token}}
|
||||
}
|
||||
|
||||
docs {
|
||||
Бизнес-endpoint требует только Bearer. Basic здесь даёт 401,
|
||||
а заголовок X-User-Id сам по себе доступа не даёт и не подменяет владельца.
|
||||
}
|
||||
|
||||
tests {
|
||||
test("status 200", function() {
|
||||
expect(res.status).to.equal(200);
|
||||
});
|
||||
|
||||
test("это тот же пользователь", function() {
|
||||
expect(res.body.id).to.equal(bru.getVar("userId"));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
meta {
|
||||
name: Register second user
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{baseUrl}}/api/v1/users
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
docs {
|
||||
Второй пользователь: нужен для чата с двумя участниками и проверки,
|
||||
что чужой чат отдаёт 404. Сохраняет secondUserId и secondUsername,
|
||||
используя тот же пароль.
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
if (!bru.getVar("suffix")) {
|
||||
bru.setVar("suffix", Math.random().toString(36).slice(2, 10));
|
||||
}
|
||||
bru.setVar("secondUsername", `demo2_${bru.getVar("suffix")}`);
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"username": "{{secondUsername}}",
|
||||
"display_name": "Второй участник",
|
||||
"password": "{{password}}"
|
||||
}
|
||||
}
|
||||
|
||||
tests {
|
||||
test("201 created", function() {
|
||||
expect(res.status).to.equal(201);
|
||||
});
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setVar("secondUserId", res.body.id);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
meta {
|
||||
name: Register third user
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{baseUrl}}/api/v1/users
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
docs {
|
||||
Третий пользователь не входит в демо-чат: нужен, чтобы показать,
|
||||
что чужой чат отдаёт 404, а не раскрывает факт существования.
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
if (!bru.getVar("suffix")) {
|
||||
bru.setVar("suffix", Math.random().toString(36).slice(2, 10));
|
||||
}
|
||||
bru.setVar("thirdUsername", `demo3_${bru.getVar("suffix")}`);
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"username": "{{thirdUsername}}",
|
||||
"display_name": "Посторонний",
|
||||
"password": "{{password}}"
|
||||
}
|
||||
}
|
||||
|
||||
tests {
|
||||
test("201 created", function() {
|
||||
expect(res.status).to.equal(201);
|
||||
});
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setVar("thirdUserId", res.body.id);
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
meta {
|
||||
name: Register first user
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
post {
|
||||
url: {{baseUrl}}/api/v1/users
|
||||
body: json
|
||||
auth: none
|
||||
}
|
||||
|
||||
body:json {
|
||||
{
|
||||
"username": "{{username}}",
|
||||
"display_name": "Демо-пользователь",
|
||||
"password": "{{password}}"
|
||||
}
|
||||
}
|
||||
|
||||
vars:pre-request {
|
||||
baseUrl: http://localhost:8080
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
if (!bru.getVar("suffix")) {
|
||||
bru.setVar("suffix", Math.random().toString(36).slice(2, 10));
|
||||
}
|
||||
bru.setVar("username", `demo_${bru.getVar("suffix")}`);
|
||||
}
|
||||
|
||||
script:post-response {
|
||||
bru.setVar("userId", res.body.id);
|
||||
bru.setVar("displayName", res.body.display_name);
|
||||
}
|
||||
|
||||
tests {
|
||||
test("201 created", function() {
|
||||
expect(res.status).to.equal(201);
|
||||
});
|
||||
|
||||
test("пароль и хеш не утекли", function() {
|
||||
expect(res.body).to.not.have.property("password");
|
||||
expect(res.body).to.not.have.property("password_hash");
|
||||
});
|
||||
}
|
||||
|
||||
docs {
|
||||
Регистрация с паролем (12–128 code points).
|
||||
Username генерируется из случайного суффикса, чтобы повторный запуск коллекции
|
||||
не упирался в 409. Сохраняет переменные: username, userId, displayName.
|
||||
Ответ никогда не содержит password или password_hash.
|
||||
}
|
||||
Reference in New Issue
Block a user