forked from mtusi2026/mtusi2026lab3
перенос 2 лабы
This commit is contained in:
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
base_url="${BASE_URL:-http://localhost:8080}"
|
||||
suffix="$(date +%s)_$RANDOM"
|
||||
# Только синтетические пароли; токены остаются в памяти shell и не выводятся.
|
||||
password="Demo-password-$suffix"
|
||||
register() {
|
||||
local username="$1" display_name="$2"
|
||||
jq -nc --arg u "$username" --arg d "$display_name" --arg p "$password" \
|
||||
'{username:$u, display_name:$d, password:$p}' |
|
||||
curl -fsS -H 'Content-Type: application/json' --data-binary @- "$base_url/api/v1/users" | jq -er '.id'
|
||||
}
|
||||
login() {
|
||||
curl -fsS -X POST -u "$1:$password" "$base_url/api/v1/auth/sessions" | jq -er '.token'
|
||||
}
|
||||
alice_id="$(register "alice_$suffix" Алиса)"
|
||||
bob_id="$(register "bob_$suffix" Боб)"
|
||||
alice_token="$(login "alice_$suffix")"
|
||||
bob_token="$(login "bob_$suffix")"
|
||||
chat_id="$(jq -nc --arg a "$alice_id" --arg b "$bob_id" '{title:"Учебный чат",member_ids:[$a,$b]}' |
|
||||
curl -fsS -H "Authorization: Bearer $alice_token" -H 'Content-Type: application/json' \
|
||||
--data-binary @- "$base_url/api/v1/chats" | jq -er '.id')"
|
||||
for token in "$alice_token" "$bob_token"; do
|
||||
curl -fsS -H "Authorization: Bearer $token" -H 'Content-Type: application/json' \
|
||||
-d '{"text":"Привет из lab2! 👋"}' "$base_url/api/v1/chats/$chat_id/messages" | jq .
|
||||
done
|
||||
curl -fsS -H "Authorization: Bearer $bob_token" "$base_url/api/v1/chats/$chat_id/messages" | jq .
|
||||
Reference in New Issue
Block a user