Skip to content

Commit f25ec1c

Browse files
committed
Test attempting to remove yourself as the only owner
1 parent 55f9853 commit f25ec1c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/tests/krate.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,24 +1294,38 @@ fn owners_can_remove_self() {
12941294
let r: R = ::json(&mut response);
12951295
assert_eq!(r.users.len(), 1);
12961296

1297+
// Deleting yourself when you're the only owner isn't allowed.
1298+
let body = r#"{"users":["firstowner"]}"#;
1299+
let mut response = ok_resp!(middle.call(req.with_method(Method::Delete).with_body(
1300+
body.as_bytes(),
1301+
)));
1302+
let json = ::json::<::Bad>(&mut response);
1303+
assert!(json.errors[0].detail.contains(
1304+
"cannot remove the sole owner of a crate",
1305+
));
1306+
12971307
let body = r#"{"users":["secondowner"]}"#;
12981308
let mut response = ok_resp!(middle.call(req.with_method(Method::Put).with_body(
12991309
body.as_bytes(),
13001310
)));
13011311
assert!(::json::<O>(&mut response).ok);
13021312

1303-
// This is a self delete from owners
1313+
// Deleting yourself when there are other owners is allowed.
13041314
let body = r#"{"users":["firstowner"]}"#;
13051315
let mut response = ok_resp!(middle.call(req.with_method(Method::Delete).with_body(
13061316
body.as_bytes(),
13071317
)));
13081318
assert!(::json::<O>(&mut response).ok);
13091319

1320+
// After you delete yourself, you no longer have permisions to manage the crate.
13101321
let body = r#"{"users":["secondowner"]}"#;
13111322
let mut response = ok_resp!(middle.call(req.with_method(Method::Delete).with_body(
13121323
body.as_bytes(),
13131324
)));
1314-
::json::<::Bad>(&mut response);
1325+
let json = ::json::<::Bad>(&mut response);
1326+
assert!(json.errors[0].detail.contains(
1327+
"only owners have permission to modify owners",
1328+
));
13151329
}
13161330

13171331
#[test]

0 commit comments

Comments
 (0)