[fix](trx-frontend-http): make Guest role composable
CI / lint (pull_request) Successful in 2m25s
CI / test (pull_request) Successful in 9m16s
CI / frontend (pull_request) Successful in 5m22s
CI / reuse (pull_request) Successful in 6s
CI / lint (push) Successful in 2m23s
CI / test (push) Successful in 8m11s
CI / frontend (push) Successful in 4m24s
CI / reuse (push) Successful in 4s
CI / lint (pull_request) Successful in 2m25s
CI / test (pull_request) Successful in 9m16s
CI / frontend (pull_request) Successful in 5m22s
CI / reuse (pull_request) Successful in 6s
CI / lint (push) Successful in 2m23s
CI / test (push) Successful in 8m11s
CI / frontend (push) Successful in 4m24s
CI / reuse (push) Successful in 4s
This commit was merged in pull request #66.
This commit is contained in:
@@ -1852,10 +1852,9 @@ function buildRoleChoices(selected) {
|
|||||||
input.addEventListener("change", () => {
|
input.addEventListener("change", () => {
|
||||||
if (!input.checked) return;
|
if (!input.checked) return;
|
||||||
if (value === "guest") {
|
if (value === "guest") {
|
||||||
inputs.forEach((choice) => {
|
const administrator = inputs.find((choice) => choice.value === "administrator");
|
||||||
if (choice.value !== "guest") choice.input.checked = false;
|
if (administrator) administrator.input.checked = false;
|
||||||
});
|
} else if (value === "administrator") {
|
||||||
} else {
|
|
||||||
const guest = inputs.find((choice) => choice.value === "guest");
|
const guest = inputs.find((choice) => choice.value === "guest");
|
||||||
if (guest) guest.input.checked = false;
|
if (guest) guest.input.checked = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -447,8 +447,9 @@ function buildRoleChoices(selected: readonly AuthRole[]) {
|
|||||||
input.addEventListener("change", () => {
|
input.addEventListener("change", () => {
|
||||||
if (!input.checked) return;
|
if (!input.checked) return;
|
||||||
if (value === "guest") {
|
if (value === "guest") {
|
||||||
inputs.forEach(choice => { if (choice.value !== "guest") choice.input.checked = false; });
|
const administrator = inputs.find(choice => choice.value === "administrator");
|
||||||
} else {
|
if (administrator) administrator.input.checked = false;
|
||||||
|
} else if (value === "administrator") {
|
||||||
const guest = inputs.find(choice => choice.value === "guest");
|
const guest = inputs.find(choice => choice.value === "guest");
|
||||||
if (guest) guest.input.checked = false;
|
if (guest) guest.input.checked = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,11 @@ try {
|
|||||||
const listenerPassword = listenerRow.locator('input[type="password"]');
|
const listenerPassword = listenerRow.locator('input[type="password"]');
|
||||||
await listenerRow.locator('input[value="guest"]').check();
|
await listenerRow.locator('input[value="guest"]').check();
|
||||||
assert.equal(await listenerPassword.isDisabled(), true);
|
assert.equal(await listenerPassword.isDisabled(), true);
|
||||||
await listenerRow.locator('input[value="read"]').check();
|
assert.equal(await listenerRow.locator('input[value="read"]').isChecked(), true);
|
||||||
|
await listenerRow.locator('input[value="control"]').check();
|
||||||
|
assert.equal(await listenerRow.locator('input[value="guest"]').isChecked(), true);
|
||||||
|
assert.equal(await listenerPassword.isDisabled(), true);
|
||||||
|
await listenerRow.locator('input[value="guest"]').uncheck();
|
||||||
assert.equal(await listenerPassword.isDisabled(), false);
|
assert.equal(await listenerPassword.isDisabled(), false);
|
||||||
assert.deepEqual(runtimeErrors, []);
|
assert.deepEqual(runtimeErrors, []);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -646,8 +646,8 @@ fn validate_roles(roles: AuthRoles) -> Result<AuthRoles, String> {
|
|||||||
if roles.is_empty() {
|
if roles.is_empty() {
|
||||||
return Err("at least one role is required".to_string());
|
return Err("at least one role is required".to_string());
|
||||||
}
|
}
|
||||||
if roles.contains(&AuthRole::Guest) && roles.len() != 1 {
|
if roles.contains(&AuthRole::Guest) && roles.contains(&AuthRole::Administrator) {
|
||||||
return Err("guest cannot be combined with other roles".to_string());
|
return Err("guest cannot be combined with administrator".to_string());
|
||||||
}
|
}
|
||||||
Ok(roles)
|
Ok(roles)
|
||||||
}
|
}
|
||||||
@@ -1428,6 +1428,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_route_access_allows() {
|
fn test_route_access_allows() {
|
||||||
let guest = roles(&[AuthRole::Guest]);
|
let guest = roles(&[AuthRole::Guest]);
|
||||||
|
let guest_control = roles(&[AuthRole::Guest, AuthRole::Control]);
|
||||||
let read = roles(&[AuthRole::Read]);
|
let read = roles(&[AuthRole::Read]);
|
||||||
let control = roles(&[AuthRole::Control]);
|
let control = roles(&[AuthRole::Control]);
|
||||||
let transmit = roles(&[AuthRole::Transmit]);
|
let transmit = roles(&[AuthRole::Transmit]);
|
||||||
@@ -1438,10 +1439,12 @@ mod tests {
|
|||||||
assert!(RouteAccess::Public.allows(Some(&administrator)));
|
assert!(RouteAccess::Public.allows(Some(&administrator)));
|
||||||
assert!(!RouteAccess::Account.allows(None));
|
assert!(!RouteAccess::Account.allows(None));
|
||||||
assert!(!RouteAccess::Account.allows(Some(&guest)));
|
assert!(!RouteAccess::Account.allows(Some(&guest)));
|
||||||
|
assert!(!RouteAccess::Account.allows(Some(&guest_control)));
|
||||||
assert!(RouteAccess::Account.allows(Some(&write)));
|
assert!(RouteAccess::Account.allows(Some(&write)));
|
||||||
|
|
||||||
assert!(!RouteAccess::Read.allows(None));
|
assert!(!RouteAccess::Read.allows(None));
|
||||||
assert!(RouteAccess::Read.allows(Some(&guest)));
|
assert!(RouteAccess::Read.allows(Some(&guest)));
|
||||||
|
assert!(RouteAccess::Control.allows(Some(&guest_control)));
|
||||||
assert!(RouteAccess::Read.allows(Some(&read)));
|
assert!(RouteAccess::Read.allows(Some(&read)));
|
||||||
assert!(RouteAccess::Read.allows(Some(&control)));
|
assert!(RouteAccess::Read.allows(Some(&control)));
|
||||||
assert!(RouteAccess::Read.allows(Some(&transmit)));
|
assert!(RouteAccess::Read.allows(Some(&transmit)));
|
||||||
@@ -1604,12 +1607,25 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn guest_is_an_exclusive_role() {
|
fn guest_can_be_combined_with_non_administrator_roles() {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
validate_roles(roles(&[AuthRole::Guest])).unwrap(),
|
validate_roles(roles(&[
|
||||||
roles(&[AuthRole::Guest])
|
AuthRole::Guest,
|
||||||
|
AuthRole::Read,
|
||||||
|
AuthRole::Control,
|
||||||
|
AuthRole::Transmit,
|
||||||
|
AuthRole::Write,
|
||||||
|
]))
|
||||||
|
.unwrap(),
|
||||||
|
roles(&[
|
||||||
|
AuthRole::Guest,
|
||||||
|
AuthRole::Read,
|
||||||
|
AuthRole::Control,
|
||||||
|
AuthRole::Transmit,
|
||||||
|
AuthRole::Write,
|
||||||
|
])
|
||||||
);
|
);
|
||||||
assert!(validate_roles(roles(&[AuthRole::Guest, AuthRole::Read])).is_err());
|
assert!(validate_roles(roles(&[AuthRole::Guest, AuthRole::Administrator])).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user