diff --git a/README.md b/README.md index 7dca620..8654d31 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ The application supports two authentication methods: 4. Make authenticated requests: ```bash - curl -X GET "http://localhost:3000/api/v1/health" \ + curl -X GET "http://localhost:3000/api/v1/info" \ -H "Authorization: Bearer " ``` @@ -91,7 +91,7 @@ The application supports two authentication methods: 2. Make authenticated requests: ```bash - curl -X GET "http://localhost:3000/api/v1/health" \ + curl -X GET "http://localhost:3000/api/v1/info" \ -H "X-API-Key: my-secret-api-key" ``` @@ -109,9 +109,9 @@ cargo run --release -- listen --host 127.0.0.1 --port 8080 ### API Endpoints -#### Health Check +#### info Check ```bash -GET /api/v1/health +GET /api/v1/info ``` #### Dictionary Management diff --git a/apps/app_api/src/api/v1.rs b/apps/app_api/src/api/v1.rs index 33690bf..a0ef1af 100644 --- a/apps/app_api/src/api/v1.rs +++ b/apps/app_api/src/api/v1.rs @@ -1,6 +1,6 @@ pub mod auth; pub mod dictionary; -pub mod health; +pub mod info; pub mod major; use crate::state::AppState; @@ -12,7 +12,7 @@ use std::sync::Arc; pub fn routes(state: Arc) -> Router> { Router::new() - .nest("/health", health::routes()) + .nest("/info", info::routes()) .nest("/auth", auth::routes()) .nest("/dicts", dictionary::routes()) .nest("/major", major::routes()) diff --git a/apps/app_api/src/api/v1/health.rs b/apps/app_api/src/api/v1/info.rs similarity index 100% rename from apps/app_api/src/api/v1/health.rs rename to apps/app_api/src/api/v1/info.rs diff --git a/config.toml b/config.toml index 347ac25..3a5c3e2 100644 --- a/config.toml +++ b/config.toml @@ -5,9 +5,9 @@ host = "0.0.0.0" port = 3000 [auth] -firebase_project_id = "test-project" -firebase_emulator_url = "http://192.168.1.23:9099" -api_tokens = ["dev-api-key"] +firebase_project_id = "phomnemic" +# firebase_emulator_url = "http://192.168.1.23:9099" +api_tokens = ["AIzaSyCCgWH9Qg5vLTMFYLTuU0tyLFKBgtBkucE", "test-api-key"] [database] url = "sqlite:app.db" diff --git a/lib/src/auth/infrastructure/jwt.rs b/lib/src/auth/infrastructure/jwt.rs index e0e7674..ca2ae4b 100644 --- a/lib/src/auth/infrastructure/jwt.rs +++ b/lib/src/auth/infrastructure/jwt.rs @@ -168,7 +168,7 @@ impl JwtAuthenticator { format!("{}/.well-known/jwks.json", emulator.trim_end_matches('/')) } else { format!( - "https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com" + "https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com" ) }; @@ -243,7 +243,9 @@ impl Authenticator for JwtAuthenticator { .kid .ok_or_else(|| AuthError::AuthenticationFailed("Token missing key ID".to_string()))?; - let public_keys = self.get_public_keys().await?; + let public_keys = self.get_public_keys().await.map_err(|e| { + AuthError::AuthenticationFailed(format!("Failed to fetch public keys: {}", e)) + })?; let decoding_key = public_keys .get(&kid) .ok_or_else(|| AuthError::AuthenticationFailed("Unknown key ID".to_string()))?; diff --git a/tavern-tests/export.sh b/tavern-tests/export.sh new file mode 100644 index 0000000..6b29a65 --- /dev/null +++ b/tavern-tests/export.sh @@ -0,0 +1,14 @@ + +if [ -d .venv ]; then + source .venv/bin/activate +else + python3 -m venv .venv + source .venv/bin/activate + pip install -r requirements.txt +fi + +export TEST_SERVER_ADDRESS="127.0.0.1:3000" +export TEST_API_BASE="/api/v1" + +export TEST_API_KEY="test-api-key" +export TEST_USER_ID="test-user-id" \ No newline at end of file diff --git a/tavern-tests/requirements.txt b/tavern-tests/requirements.txt new file mode 100644 index 0000000..166ce3f --- /dev/null +++ b/tavern-tests/requirements.txt @@ -0,0 +1,3 @@ +pyyaml +tavern +allure-pytest diff --git a/tavern-tests/tavern-run-all.sh b/tavern-tests/tavern-run-all.sh new file mode 100755 index 0000000..0293f0b --- /dev/null +++ b/tavern-tests/tavern-run-all.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +if [ -z "$TEST_SERVER_ADDRESS" ]; then + source export.sh +fi + +tavern-ci --alluredir=reports test_plans/info_test.tavern.yaml + +if command -v allure > /dev/null; then + allure generate --clean --single-file --output /tmp/vm-allure-report --name index.html reports +fi + +# allure package: https://github.com/allure-framework/allure2/releases/download/2.34.0/allure_2.34.0-1_all.deb diff --git a/tavern-tests/tavern-run-single.sh b/tavern-tests/tavern-run-single.sh new file mode 100755 index 0000000..51c1a00 --- /dev/null +++ b/tavern-tests/tavern-run-single.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +if [ -z "$TEST_SERVER_ADDRESS" ]; then + source export.sh +fi + +tavern-ci --alluredir=reports $1 + +allure generate --clean --single-file --output /tmp/vm-allure-report --name index.html reports + +# allure package: https://github.com/allure-framework/allure2/releases/download/2.34.0/allure_2.34.0-1_all.deb diff --git a/tavern-tests/test_plans/common_stages.yaml b/tavern-tests/test_plans/common_stages.yaml new file mode 100644 index 0000000..0e4d102 --- /dev/null +++ b/tavern-tests/test_plans/common_stages.yaml @@ -0,0 +1,29 @@ +--- + +stages: + - id: clear_test_user + name: "Purge test user data" + request: + url: "http://{server_address}/{api_base}/user/{test_user_id}/clear" + method: POST + headers: + Content-Type: application/json + Authorization: Bearer {api_key} + response: + strict: False + status_code: 200 + + - id: register_test_user + name: "Register test user" + request: + url: "http://{server_address}/{api_base}/user" + method: POST + headers: + Content-Type: application/json + Authorization: Bearer {api_key} + body: + username: {test_user_id} + password: password + response: + strict: False + status_code: 201 diff --git a/tavern-tests/test_plans/includes.yaml b/tavern-tests/test_plans/includes.yaml new file mode 100644 index 0000000..54c2bfb --- /dev/null +++ b/tavern-tests/test_plans/includes.yaml @@ -0,0 +1,5 @@ +variables: + server_address: "{tavern.env_vars.TEST_SERVER_ADDRESS}" + api_base: "{tavern.env_vars.TEST_API_BASE}" + api_key: "{tavern.env_vars.TEST_API_KEY}" + user_id: "{tavern.env_vars.TEST_USER_ID}" diff --git a/tavern-tests/test_plans/info_test.tavern.yaml b/tavern-tests/test_plans/info_test.tavern.yaml new file mode 100644 index 0000000..87c82b8 --- /dev/null +++ b/tavern-tests/test_plans/info_test.tavern.yaml @@ -0,0 +1,19 @@ +test_name: "Test server API info endpoint" + +includes: + - !include includes.yaml + +stages: + - name: "Check version" + request: + url: "http://{server_address}/{api_base}/info/version" + method: GET + headers: + X-API-Key: "{api_key}" + response: + strict: False + status_code: 200 + json: + name: !anystr + version: !anystr +