1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
use forgejo_api::structs::*;
mod common;
#[tokio::test]
async fn user() {
let api = common::login();
let user_opt = CreateUserOption {
created_at: None,
email: "pipis@noreply.example.org".into(),
full_name: None,
login_name: None,
must_change_password: None,
password: Some("userpass".into()),
restricted: Some(false),
send_notify: Some(true),
source_id: None,
username: "Pipis".into(),
visibility: Some("public".into()),
};
let _ = api
.admin_create_user(user_opt)
.await
.expect("failed to create user");
let query = AdminSearchUsersQuery::default();
let (_, users) = api
.admin_search_users(query)
.await
.expect("failed to search users");
assert!(
users.iter().any(|u| u.login.as_ref().unwrap() == "Pipis"),
"could not find new user"
);
let users = api
.admin_get_all_emails()
.await
.expect("failed to search emails");
assert!(
users
.iter()
.any(|u| u.email.as_ref().unwrap() == "pipis@noreply.example.org"),
"could not find new user"
);
let rename_opt = RenameUserOption {
new_username: "Bepis".into(),
};
api.admin_rename_user("Pipis", rename_opt)
.await
.expect("failed to rename user");
let query = AdminDeleteUserQuery { purge: Some(true) };
api.admin_delete_user("Bepis", query)
.await
.expect("failed to delete user");
let query = AdminDeleteUserQuery { purge: Some(true) };
assert!(
api.admin_delete_user("Ghost", query).await.is_err(),
"deleting fake user should fail"
);
}
#[tokio::test]
async fn org() {
let api = common::login();
let user_opt = CreateUserOption {
created_at: None,
email: "org-owner@noreply.example.org".into(),
full_name: None,
login_name: None,
must_change_password: None,
password: Some("userpass".into()),
restricted: Some(false),
send_notify: Some(true),
source_id: None,
username: "OrgOwner".into(),
visibility: Some("public".into()),
};
let _ = api
.admin_create_user(user_opt)
.await
.expect("failed to create user");
let org_opt = CreateOrgOption {
description: None,
email: None,
full_name: None,
location: None,
repo_admin_change_team_access: None,
username: "test-org".into(),
visibility: Some(CreateOrgOptionVisibility::Public),
website: None,
};
let _ = api
.admin_create_org("OrgOwner", org_opt)
.await
.expect("failed to create org");
assert!(
!api.admin_get_all_orgs().await.unwrap().1.is_empty(),
"org list empty"
);
}
#[tokio::test]
async fn key() {
let api = common::login();
let user_opt = CreateUserOption {
created_at: None,
email: "key-holder@noreply.example.org".into(),
full_name: None,
login_name: None,
must_change_password: None,
password: Some("userpass".into()),
restricted: Some(false),
send_notify: Some(true),
source_id: None,
username: "KeyHolder".into(),
visibility: Some("public".into()),
};
let _ = api
.admin_create_user(user_opt)
.await
.expect("failed to create user");
let key_opt = CreateKeyOption {
key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIN68ehQAsbGEwlXPa2AxbAh1QxFQrtRel2jeC0hRlPc1 user@noreply.example.org".into(),
read_only: None,
title: "Example Key".into(),
};
let key = api
.admin_create_public_key("KeyHolder", key_opt)
.await
.expect("failed to create key");
api.admin_delete_user_public_key("KeyHolder", key.id.unwrap())
.await
.expect("failed to delete key");
}
#[tokio::test]
async fn cron() {
let api = common::login();
let (_, crons) = api
.admin_cron_list()
.await
.expect("failed to get crons list");
api.admin_cron_run(crons.first().expect("no crons").name.as_ref().unwrap())
.await
.expect("failed to run cron");
}
#[tokio::test]
async fn hook() {
let api = common::login();
let hook_opt = CreateHookOption {
active: None,
authorization_header: None,
branch_filter: None,
config: CreateHookOptionConfig {
content_type: "json".into(),
url: url::Url::parse("http://test.local/").unwrap(),
additional: Default::default(),
},
events: Some(Vec::new()),
r#type: CreateHookOptionType::Gitea,
};
// yarr har har me matey this is me hook
let hook = api
.admin_create_hook(hook_opt)
.await
.expect("failed to create hook");
let edit_hook = EditHookOption {
active: Some(true),
authorization_header: None,
branch_filter: None,
config: None,
events: None,
};
api.admin_edit_hook(hook.id.unwrap(), edit_hook)
.await
.expect("failed to edit hook");
api.admin_delete_hook(hook.id.unwrap())
.await
.expect("failed to delete hook");
}
#[tokio::test]
async fn quota_group() {
let api = common::login();
let user_opts = CreateUserOption {
created_at: None,
email: "1997@example.com".into(),
full_name: None,
login_name: None,
must_change_password: None,
password: Some("dialtone".into()),
restricted: None,
send_notify: None,
source_id: None,
username: "salesman".into(),
visibility: None,
};
api.admin_create_user(user_opts)
.await
.expect("failed to create user");
let group = CreateQuotaGroupOptions {
name: Some("no doing anything".into()),
rules: Some(vec![CreateQuotaRuleOptions {
limit: Some(0),
name: Some("blah".into()),
subjects: Some(vec![CreateQuotaRuleOptionsSubjects::SizeAll]),
}]),
};
let quota_group = api
.admin_create_quota_group(group)
.await
.expect("failed to create quota group");
api.admin_add_user_to_quota_group("no doing anything", "salesman")
.await
.expect("failed to add user to quota group");
assert!(quota_group
.name
.as_ref()
.is_some_and(|name| name == "no doing anything"));
assert!(quota_group
.rules
.as_ref()
.is_some_and(|rules| rules.len() == 1));
let (_, quota_groups) = api
.admin_list_quota_groups()
.await
.expect("failed to list quota groups");
assert_eq!(quota_groups.len(), 1);
assert_eq!("a_groups[0], "a_group);
let quota_info = api
.admin_get_user_quota("salesman")
.await
.expect("failed to get user quota");
let usage = quota_info
.used
.expect("quota info missing usage info")
.size
.expect("quota info missing size info");
assert!(usage
.git
.is_some_and(|git| git.lfs.is_some_and(|lfs| lfs == 0)));
assert!(usage
.repos
.as_ref()
.is_some_and(|repos| repos.public.is_some_and(|lfs| lfs == 0)));
assert!(usage
.repos
.is_some_and(|repos| repos.private.is_some_and(|lfs| lfs == 0)));
assert!(usage
.assets
.is_some_and(|assets| assets.artifacts.is_some_and(|lfs| lfs == 0)));
api.admin_remove_rule_from_quota_group("no doing anything", "blah")
.await
.expect("failed to delete rule from quota group");
api.admin_remove_user_from_quota_group("no doing anything", "salesman")
.await
.expect("failed to remove user from quota group");
api.admin_delete_quota_group("no doing anything")
.await
.expect("failed to delete quota group");
}
|