Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

2.2 KB
Raw Blame
use wiremock::matchers::{body_json, header, method, path, query_param_is_missing};
use wiremock::{Mock, MockServer, ResponseTemplate};

use crate::FusionAuthClient;

fn client(base_url: String) -> FusionAuthClient {
    FusionAuthClient::new(
        "api-key".into(),
        "application-id".into(),
        "client-secret".into(),
        base_url,
        "http://localhost:28011/oauth/redirect".into(),
        "google-client-id".into(),
        "google-client-secret".into(),
    )
}

#[tokio::test]
async fn revoke_refresh_token_sends_the_token_as_json() {
    let server = MockServer::start().await;
    Mock::given(method("DELETE"))
        .and(path("/api/jwt/refresh"))
        .and(header("authorization", "api-key"))
        .and(header("content-type", "application/json"))
        .and(body_json(serde_json::json!({ "token": "refresh-token" })))
        .and(query_param_is_missing("token"))
        .respond_with(ResponseTemplate::new(200))
        .expect(1)
        .mount(&server)
        .await;

    client(server.uri())
        .revoke_refresh_token("refresh-token")
        .await
        .expect("revocation should succeed");
}

#[tokio::test]
async fn revoke_refresh_token_treats_an_unknown_token_as_revoked() {
    let server = MockServer::start().await;
    Mock::given(method("DELETE"))
        .and(path("/api/jwt/refresh"))
        .respond_with(ResponseTemplate::new(404))
        .expect(1)
        .mount(&server)
        .await;

    client(server.uri())
        .revoke_refresh_token("already-revoked")
        .await
        .expect("an unknown token is already revoked");
}

#[tokio::test]
async fn revoke_refresh_token_reports_a_server_error() {
    let server = MockServer::start().await;
    Mock::given(method("DELETE"))
        .and(path("/api/jwt/refresh"))
        .respond_with(ResponseTemplate::new(503).set_body_string("unavailable"))
        .expect(1)
        .mount(&server)
        .await;

    let error = client(server.uri())
        .revoke_refresh_token("refresh-token")
        .await
        .expect_err("a server error must not count as a revocation");
    assert_eq!(
        error.upstream().map(|upstream| upstream.failure),
        Some(upstream_error::UpstreamFailure::Unavailable)
    );
}