tests for the ci metrics, builder and hive forge accounts
This commit is contained in:
parent
c1234973be
commit
3032f34269
4 changed files with 493 additions and 1 deletions
|
|
@ -2851,7 +2851,10 @@ mod tests {
|
||||||
status,
|
status,
|
||||||
[
|
[
|
||||||
(CONTENT_TYPE, "application/json".to_owned()),
|
(CONTENT_TYPE, "application/json".to_owned()),
|
||||||
(axum::http::HeaderName::from_static("x-total-count"), total.to_string()),
|
(
|
||||||
|
axum::http::HeaderName::from_static("x-total-count"),
|
||||||
|
total.to_string(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
answer,
|
answer,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -309,4 +309,49 @@ mod tests {
|
||||||
assert_eq!(body["max_repo_creation"], 0);
|
assert_eq!(body["max_repo_creation"], 0);
|
||||||
assert_eq!(body["allow_create_organization"], false);
|
assert_eq!(body["allow_create_organization"], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The account is created, its email checked, and it is locked out of
|
||||||
|
/// creating repos and organizations, in that order.
|
||||||
|
#[tokio::test]
|
||||||
|
async fn the_account_is_created_and_locked_out_of_creating_repos() {
|
||||||
|
use super::super::tests::{lockdown_patch, stub_forge, writes};
|
||||||
|
|
||||||
|
let (client, seen) = stub_forge(
|
||||||
|
(201, "{}"),
|
||||||
|
(200, r#"{"email":"builder@services.hyperhive.local"}"#),
|
||||||
|
(200, "{}"),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
client.ensure_builder_user().await.unwrap();
|
||||||
|
let lock = lockdown_patch(&seen, LOGIN).expect("lockdown sent");
|
||||||
|
assert_eq!(lock["max_repo_creation"], 0);
|
||||||
|
assert_eq!(lock["allow_create_organization"], false);
|
||||||
|
assert_eq!(lock["login_name"], LOGIN);
|
||||||
|
assert_eq!(
|
||||||
|
writes(&seen),
|
||||||
|
[
|
||||||
|
"POST /api/v1/admin/users".to_owned(),
|
||||||
|
format!("PATCH /api/v1/admin/users/{LOGIN}")
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_refused_create_or_lockdown_fails_the_job() {
|
||||||
|
use super::super::tests::stub_forge;
|
||||||
|
|
||||||
|
let email = (200, r#"{"email":"builder@services.hyperhive.local"}"#);
|
||||||
|
let (client, seen) = stub_forge((500, r#"{"message":"x"}"#), email, (200, "{}")).await;
|
||||||
|
client
|
||||||
|
.ensure_builder_user()
|
||||||
|
.await
|
||||||
|
.expect_err("create refused");
|
||||||
|
assert_eq!(seen.lock().unwrap().len(), 1, "nothing is sent after it");
|
||||||
|
|
||||||
|
let (client, _) = stub_forge((201, "{}"), email, (500, r#"{"message":"x"}"#)).await;
|
||||||
|
client
|
||||||
|
.ensure_builder_user()
|
||||||
|
.await
|
||||||
|
.expect_err("a lockdown that failed is not a built account");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -494,4 +494,273 @@ mod tests {
|
||||||
assert_eq!(body["max_repo_creation"], 0);
|
assert_eq!(body["max_repo_creation"], 0);
|
||||||
assert_eq!(body["allow_create_organization"], false);
|
assert_eq!(body["allow_create_organization"], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The forge side, against a stand-in forge that answers by path.
|
||||||
|
use super::super::tests::{Seen as Requests, routed_forge, sent, writes};
|
||||||
|
use serde_json::{Value, json};
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
|
fn team_json(id: i64, permission: &str, units: &[&str]) -> Value {
|
||||||
|
json!({
|
||||||
|
"id": id,
|
||||||
|
"name": TEAM,
|
||||||
|
"description": TEAM_DESCRIPTION,
|
||||||
|
"permission": permission,
|
||||||
|
"includes_all_repositories": true,
|
||||||
|
"can_create_org_repo": false,
|
||||||
|
"units": units,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A forge listing `orgs` and giving each the teams in `teams`, every
|
||||||
|
/// request not named by `rest` a 201 for a POST and 200 otherwise.
|
||||||
|
async fn forge_of(
|
||||||
|
orgs: &[&str],
|
||||||
|
teams: Vec<(&'static str, u16, Value)>,
|
||||||
|
rest: Vec<(String, u16, Value)>,
|
||||||
|
) -> (Client, Requests) {
|
||||||
|
let orgs: Vec<Value> = orgs.iter().map(|o| json!({"username": o})).collect();
|
||||||
|
let teams: Vec<(String, u16, Value)> = teams
|
||||||
|
.into_iter()
|
||||||
|
.map(|(k, s, b)| (k.to_owned(), s, b))
|
||||||
|
.collect();
|
||||||
|
routed_forge(move |method, path, _| {
|
||||||
|
let key = format!("{method} {path}");
|
||||||
|
if key == "GET /api/v1/admin/orgs" {
|
||||||
|
return (200, json!(orgs).to_string());
|
||||||
|
}
|
||||||
|
if let Some((_, s, b)) = teams.iter().chain(rest.iter()).find(|(k, _, _)| *k == key) {
|
||||||
|
return (*s, b.to_string());
|
||||||
|
}
|
||||||
|
match method {
|
||||||
|
"GET" => (404, r#"{"message":"no"}"#.to_owned()),
|
||||||
|
"POST" => (201, "{}".to_owned()),
|
||||||
|
_ => (200, "{}".to_owned()),
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn the_account_is_created_and_locked_out_of_creating_repos() {
|
||||||
|
let (client, seen) = forge_of(
|
||||||
|
&[],
|
||||||
|
vec![],
|
||||||
|
vec![at(
|
||||||
|
"GET /api/v1/users/ci-metrics",
|
||||||
|
200,
|
||||||
|
json!({"email": EMAIL}),
|
||||||
|
)],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
client.ensure_ci_metrics_user().await.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
writes(&seen),
|
||||||
|
[
|
||||||
|
"POST /api/v1/admin/users".to_owned(),
|
||||||
|
"PATCH /api/v1/admin/users/ci-metrics".to_owned()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
let lock = sent(&seen, "PATCH", "/api/v1/admin/users/ci-metrics").unwrap();
|
||||||
|
assert_eq!(lock["max_repo_creation"], 0);
|
||||||
|
assert_eq!(lock["allow_create_organization"], false);
|
||||||
|
assert_eq!(lock["login_name"], LOGIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_refused_create_stops_before_the_account_is_read_or_locked() {
|
||||||
|
let (client, seen) = forge_of(
|
||||||
|
&[],
|
||||||
|
vec![],
|
||||||
|
vec![
|
||||||
|
at("POST /api/v1/admin/users", 500, json!({"message": "x"})),
|
||||||
|
at("GET /api/v1/users/ci-metrics", 200, json!({"email": EMAIL})),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
client.ensure_ci_metrics_user().await.expect_err("refused");
|
||||||
|
assert_eq!(writes(&seen), ["POST /api/v1/admin/users"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_team_that_matches_is_left_and_one_with_the_wrong_grant_is_put_back() {
|
||||||
|
let path = "GET /api/v1/orgs/o/teams";
|
||||||
|
let (client, seen) = forge_of(
|
||||||
|
&[],
|
||||||
|
vec![(path, 200, json!([team_json(3, "read", &TEAM_UNITS)]))],
|
||||||
|
vec![],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(client.ensure_ci_metrics_team("o").await.unwrap(), 3);
|
||||||
|
assert!(writes(&seen).is_empty());
|
||||||
|
|
||||||
|
let wide = team_json(3, "write", &["repo.actions", "repo.code"]);
|
||||||
|
let (client, seen) = forge_of(&[], vec![(path, 200, json!([wide]))], vec![]).await;
|
||||||
|
assert_eq!(client.ensure_ci_metrics_team("o").await.unwrap(), 3);
|
||||||
|
assert_eq!(writes(&seen), ["PATCH /api/v1/teams/3"]);
|
||||||
|
let edit = sent(&seen, "PATCH", "/api/v1/teams/3").unwrap();
|
||||||
|
assert_eq!(edit["permission"], "read");
|
||||||
|
assert_eq!(edit["units"], json!(TEAM_UNITS));
|
||||||
|
assert_eq!(edit["includes_all_repositories"], true);
|
||||||
|
assert_eq!(edit["can_create_org_repo"], false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_missing_team_is_created_read_only_on_actions_and_a_missing_id_fails() {
|
||||||
|
let list = ("GET /api/v1/orgs/o/teams", 200, json!([]));
|
||||||
|
let (client, seen) = forge_of(
|
||||||
|
&[],
|
||||||
|
vec![list.clone()],
|
||||||
|
vec![at("POST /api/v1/orgs/o/teams", 201, json!({"id": 11}))],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(client.ensure_ci_metrics_team("o").await.unwrap(), 11);
|
||||||
|
let team = sent(&seen, "POST", "/api/v1/orgs/o/teams").unwrap();
|
||||||
|
assert_eq!(team["name"], TEAM);
|
||||||
|
assert_eq!(team["permission"], "read");
|
||||||
|
assert_eq!(team["units"], json!(TEAM_UNITS));
|
||||||
|
assert_eq!(team["includes_all_repositories"], true);
|
||||||
|
assert_eq!(team["can_create_org_repo"], false);
|
||||||
|
|
||||||
|
let (client, _) = forge_of(&[], vec![list], vec![]).await;
|
||||||
|
client
|
||||||
|
.ensure_ci_metrics_team("o")
|
||||||
|
.await
|
||||||
|
.expect_err("created, but no id came back");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn an_unreadable_team_list_is_an_error_and_never_a_create() {
|
||||||
|
let (client, seen) = forge_of(
|
||||||
|
&[],
|
||||||
|
vec![("GET /api/v1/orgs/o/teams", 500, json!({"message": "x"}))],
|
||||||
|
vec![],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
client
|
||||||
|
.ensure_ci_metrics_team("o")
|
||||||
|
.await
|
||||||
|
.expect_err("unknown");
|
||||||
|
assert!(writes(&seen).is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_duplicate_create_is_found_by_a_re_read_and_a_refusal_with_no_team_fails() {
|
||||||
|
let reads = Arc::new(AtomicUsize::new(0));
|
||||||
|
let counted = Arc::clone(&reads);
|
||||||
|
let (client, _) = routed_forge(move |method, path, _| match (method, path) {
|
||||||
|
("GET", "/api/v1/orgs/o/teams") if counted.fetch_add(1, Ordering::SeqCst) == 0 => {
|
||||||
|
(200, "[]".to_owned())
|
||||||
|
}
|
||||||
|
("GET", "/api/v1/orgs/o/teams") => {
|
||||||
|
(200, json!([team_json(4, "read", &TEAM_UNITS)]).to_string())
|
||||||
|
}
|
||||||
|
("POST", _) => (409, r#"{"message":"exists"}"#.to_owned()),
|
||||||
|
_ => (200, "{}".to_owned()),
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
assert_eq!(client.ensure_ci_metrics_team("o").await.unwrap(), 4);
|
||||||
|
|
||||||
|
let (client, _) = forge_of(
|
||||||
|
&[],
|
||||||
|
vec![("GET /api/v1/orgs/o/teams", 200, json!([]))],
|
||||||
|
vec![at(
|
||||||
|
"POST /api/v1/orgs/o/teams",
|
||||||
|
409,
|
||||||
|
json!({"message": "x"}),
|
||||||
|
)],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
client
|
||||||
|
.ensure_ci_metrics_team("o")
|
||||||
|
.await
|
||||||
|
.expect_err("not found again");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn every_page_of_organisations_is_read() {
|
||||||
|
let asked = Arc::new(AtomicUsize::new(0));
|
||||||
|
let counted = Arc::clone(&asked);
|
||||||
|
let (client, _) = routed_forge(move |_, path, _| {
|
||||||
|
assert_eq!(path, "/api/v1/admin/orgs");
|
||||||
|
let page = counted.fetch_add(1, Ordering::SeqCst);
|
||||||
|
let n = if page == 0 { ORG_PAGE as usize } else { 1 };
|
||||||
|
let orgs: Vec<Value> = (0..n)
|
||||||
|
.map(|i| json!({"username": format!("org-{page}-{i}")}))
|
||||||
|
.collect();
|
||||||
|
(200, json!(orgs).to_string())
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
let names = client.all_orgs().await.unwrap();
|
||||||
|
assert_eq!(names.len(), ORG_PAGE as usize + 1);
|
||||||
|
assert_eq!(asked.load(Ordering::SeqCst), 2);
|
||||||
|
assert_eq!(names.last().unwrap(), "org-1-0");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn at(key: &str, status: u16, body: Value) -> (String, u16, Value) {
|
||||||
|
(key.to_owned(), status, body)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn member(id: i64) -> (String, u16, Value) {
|
||||||
|
at(
|
||||||
|
&format!("GET /api/v1/teams/{id}/members/ci-metrics"),
|
||||||
|
200,
|
||||||
|
json!({}),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn the_grants_are_complete_only_when_every_org_has_the_team_with_the_account_in_it() {
|
||||||
|
let teams = |ok: bool| {
|
||||||
|
vec![
|
||||||
|
(
|
||||||
|
"GET /api/v1/orgs/a/teams",
|
||||||
|
200,
|
||||||
|
json!([team_json(1, "read", &TEAM_UNITS)]),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"GET /api/v1/orgs/b/teams",
|
||||||
|
200,
|
||||||
|
if ok {
|
||||||
|
json!([team_json(2, "read", &TEAM_UNITS)])
|
||||||
|
} else {
|
||||||
|
json!([])
|
||||||
|
},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
};
|
||||||
|
let members = vec![member(1), member(2)];
|
||||||
|
let (client, _) = forge_of(&["a", "b"], teams(true), members.clone()).await;
|
||||||
|
assert_eq!(client.observe_ci_metrics_grants().await, Some(true));
|
||||||
|
|
||||||
|
// A team missing in one org.
|
||||||
|
let (client, _) = forge_of(&["a", "b"], teams(false), members.clone()).await;
|
||||||
|
assert_eq!(client.observe_ci_metrics_grants().await, Some(false));
|
||||||
|
|
||||||
|
// The account missing from a team (404), against a failed read (500).
|
||||||
|
let (client, _) = forge_of(&["a", "b"], teams(true), vec![member(1)]).await;
|
||||||
|
assert_eq!(client.observe_ci_metrics_grants().await, Some(false));
|
||||||
|
let (client, _) = forge_of(
|
||||||
|
&["a", "b"],
|
||||||
|
teams(true),
|
||||||
|
vec![
|
||||||
|
member(1),
|
||||||
|
at(
|
||||||
|
"GET /api/v1/teams/2/members/ci-metrics",
|
||||||
|
500,
|
||||||
|
json!({"message": "x"}),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(client.observe_ci_metrics_grants().await, None);
|
||||||
|
|
||||||
|
// An unreadable team list, and an unreadable org list.
|
||||||
|
let mut unreadable = teams(true);
|
||||||
|
unreadable[1] = ("GET /api/v1/orgs/b/teams", 500, json!({"message": "x"}));
|
||||||
|
let (client, _) = forge_of(&["a", "b"], unreadable, members).await;
|
||||||
|
assert_eq!(client.observe_ci_metrics_grants().await, None);
|
||||||
|
let (client, _) = routed_forge(|_, _, _| (500, r#"{"message":"x"}"#.to_owned())).await;
|
||||||
|
assert_eq!(client.observe_ci_metrics_grants().await, None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -695,4 +695,179 @@ mod tests {
|
||||||
some_repos.includes_all_repositories = Some(false);
|
some_repos.includes_all_repositories = Some(false);
|
||||||
assert!(!hives_team_matches(&some_repos));
|
assert!(!hives_team_matches(&some_repos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The forge side, against a stand-in forge that answers by path.
|
||||||
|
use super::super::tests::{routed_forge, sent, writes};
|
||||||
|
use serde_json::{Value, json};
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
|
const TEAMS: &str = "/api/v1/orgs/agent-configs/teams";
|
||||||
|
|
||||||
|
fn hives_team_json(permission: &str, units: &[&str]) -> Value {
|
||||||
|
json!({
|
||||||
|
"id": 9,
|
||||||
|
"name": HIVES_TEAM,
|
||||||
|
"description": HIVES_TEAM_DESCRIPTION,
|
||||||
|
"permission": permission,
|
||||||
|
"includes_all_repositories": true,
|
||||||
|
"can_create_org_repo": false,
|
||||||
|
"units": units,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A forge answering the team list with `teams` and every other request
|
||||||
|
/// by `rest`, defaulting to 201 for a POST and 200 otherwise.
|
||||||
|
async fn teams_forge(
|
||||||
|
teams: (u16, Value),
|
||||||
|
rest: Vec<(&'static str, u16, Value)>,
|
||||||
|
) -> (Client, super::super::tests::Seen) {
|
||||||
|
routed_forge(move |method, path, _| {
|
||||||
|
let key = format!("{method} {path}");
|
||||||
|
if key == format!("GET {TEAMS}") {
|
||||||
|
return (teams.0, teams.1.to_string());
|
||||||
|
}
|
||||||
|
if let Some((_, status, body)) = rest.iter().find(|(k, _, _)| *k == key) {
|
||||||
|
return (*status, body.to_string());
|
||||||
|
}
|
||||||
|
(if method == "POST" { 201 } else { 200 }, "{}".to_owned())
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_hives_team_that_matches_is_used_as_it_is() {
|
||||||
|
let ok = hives_team_json("read", &HIVES_TEAM_UNITS);
|
||||||
|
let (client, seen) = teams_forge((200, json!([ok])), vec![]).await;
|
||||||
|
assert_eq!(client.ensure_hives_team().await.unwrap(), 9);
|
||||||
|
assert!(writes(&seen).is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_hives_team_with_a_wider_grant_is_put_back_to_read_on_code_and_pulls() {
|
||||||
|
let wide = hives_team_json("write", &["repo.code", "repo.pulls", "repo.issues"]);
|
||||||
|
let (client, seen) = teams_forge((200, json!([wide])), vec![]).await;
|
||||||
|
assert_eq!(client.ensure_hives_team().await.unwrap(), 9);
|
||||||
|
assert_eq!(writes(&seen), ["PATCH /api/v1/teams/9"]);
|
||||||
|
let edit = sent(&seen, "PATCH", "/api/v1/teams/9").unwrap();
|
||||||
|
assert_eq!(edit["permission"], "read");
|
||||||
|
assert_eq!(edit["units"], json!(HIVES_TEAM_UNITS));
|
||||||
|
assert_eq!(edit["includes_all_repositories"], true);
|
||||||
|
assert_eq!(edit["can_create_org_repo"], false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_missing_hives_team_is_created_read_only_and_its_id_returned() {
|
||||||
|
let (client, seen) = teams_forge(
|
||||||
|
(200, json!([])),
|
||||||
|
vec![(
|
||||||
|
"POST /api/v1/orgs/agent-configs/teams",
|
||||||
|
201,
|
||||||
|
json!({"id": 5}),
|
||||||
|
)],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
assert_eq!(client.ensure_hives_team().await.unwrap(), 5);
|
||||||
|
let team = sent(&seen, "POST", TEAMS).unwrap();
|
||||||
|
assert_eq!(team["name"], HIVES_TEAM);
|
||||||
|
assert_eq!(team["permission"], "read");
|
||||||
|
assert_eq!(team["units"], json!(HIVES_TEAM_UNITS));
|
||||||
|
assert_eq!(team["includes_all_repositories"], true);
|
||||||
|
assert_eq!(team["can_create_org_repo"], false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_created_team_with_no_id_and_an_unreadable_team_list_both_fail() {
|
||||||
|
let (client, _) = teams_forge((200, json!([])), vec![]).await;
|
||||||
|
client
|
||||||
|
.ensure_hives_team()
|
||||||
|
.await
|
||||||
|
.expect_err("a team the forge gave no id for is no team");
|
||||||
|
let (client, seen) = teams_forge((500, json!({"message": "x"})), vec![]).await;
|
||||||
|
client
|
||||||
|
.ensure_hives_team()
|
||||||
|
.await
|
||||||
|
.expect_err("an unreadable list is never answered with a create");
|
||||||
|
assert!(writes(&seen).is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_duplicate_create_finds_the_team_by_a_re_read() {
|
||||||
|
let reads = Arc::new(AtomicUsize::new(0));
|
||||||
|
let counted = Arc::clone(&reads);
|
||||||
|
let (client, _) = routed_forge(move |method, path, _| match (method, path) {
|
||||||
|
("GET", TEAMS) if counted.fetch_add(1, Ordering::SeqCst) == 0 => (200, "[]".to_owned()),
|
||||||
|
("GET", TEAMS) => (
|
||||||
|
200,
|
||||||
|
json!([hives_team_json("read", &HIVES_TEAM_UNITS)]).to_string(),
|
||||||
|
),
|
||||||
|
("POST", TEAMS) => (409, r#"{"message":"exists"}"#.to_owned()),
|
||||||
|
_ => (200, "{}".to_owned()),
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
assert_eq!(client.ensure_hives_team().await.unwrap(), 9);
|
||||||
|
assert_eq!(reads.load(Ordering::SeqCst), 2);
|
||||||
|
|
||||||
|
// Control: the same refusal with the team still absent is an error.
|
||||||
|
let (client, _) = teams_forge(
|
||||||
|
(200, json!([])),
|
||||||
|
vec![(
|
||||||
|
"POST /api/v1/orgs/agent-configs/teams",
|
||||||
|
409,
|
||||||
|
json!({"message": "x"}),
|
||||||
|
)],
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
client.ensure_hives_team().await.expect_err("nothing found");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_hive_account_is_created_and_locked_out_of_creating_repos() {
|
||||||
|
let email = hive_email("alpha");
|
||||||
|
let login = forge::hive_login("alpha");
|
||||||
|
let user = format!("/api/v1/admin/users/{login}");
|
||||||
|
let body = json!({"email": email}).to_string();
|
||||||
|
let (client, seen) = routed_forge(move |method, path, _| match method {
|
||||||
|
"GET" if path == format!("/api/v1/users/{}", forge::hive_login("alpha")) => {
|
||||||
|
(200, body.clone())
|
||||||
|
}
|
||||||
|
"POST" => (201, "{}".to_owned()),
|
||||||
|
_ => (200, "{}".to_owned()),
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
client.ensure_hive_user("alpha", &login).await.unwrap();
|
||||||
|
let lock = sent(&seen, "PATCH", &user).expect("lockdown sent");
|
||||||
|
assert_eq!(lock["max_repo_creation"], 0);
|
||||||
|
assert_eq!(lock["allow_create_organization"], false);
|
||||||
|
assert_eq!(lock["login_name"], login);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn a_failed_account_create_stops_before_the_lockdown() {
|
||||||
|
let (client, seen) = routed_forge(|method, _, _| match method {
|
||||||
|
"POST" => (500, r#"{"message":"x"}"#.to_owned()),
|
||||||
|
_ => (200, "{}".to_owned()),
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
client
|
||||||
|
.ensure_hive_user("alpha", &forge::hive_login("alpha"))
|
||||||
|
.await
|
||||||
|
.expect_err("the forge refused the create");
|
||||||
|
assert!(writes(&seen).iter().all(|w| w.starts_with("POST")));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_hive_missing_from_the_roster_is_never_queued_and_its_token_is_not_touched() {
|
||||||
|
let stale = seen(Observed::Decided(Decision::Conflict), Some(false));
|
||||||
|
let mint = seen(
|
||||||
|
Observed::Decided(Decision::Mint(MintReason::NotStored)),
|
||||||
|
Some(true),
|
||||||
|
);
|
||||||
|
// Only the hives the pass was given are judged; the roster is the whole truth.
|
||||||
|
assert_eq!(
|
||||||
|
plan(TeamSeen::Matches(1), &[("kept".to_owned(), mint)]),
|
||||||
|
["kept"]
|
||||||
|
);
|
||||||
|
assert!(plan(TeamSeen::Absent, &[]).is_empty());
|
||||||
|
assert!(plan(TeamSeen::Matches(1), &[("removed".to_owned(), stale)]).is_empty());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue