mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(iam): implement CreateLoginProfile, UpdateLoginProfile, DeleteLoginProfile (#3865)
* feat(iam): implement CreateLoginProfile, UpdateLoginProfile, DeleteLoginProfile GetLoginProfile previously existed as a permanent stub always returning NoSuchEntity, and the docs claimed the other three actions were supported even though the query handler had no case for them at all. Adds a LoginProfile model and the full lifecycle on IamService: a user holds at most one login profile, Create/Get/Delete default UserName to the caller's resolved identity (matching AWS), Update requires it explicitly, and Update leaves an omitted field (Password or PasswordResetRequired) unchanged rather than resetting it. The password is validated against AWS's wire character-class/length rule and, when the account has one, against the existing account password policy (PasswordPolicyViolation). Verified against the real AWS IAM API reference for all four actions' request/response shapes and error lists. * fix(iam): block DeleteUser on a login profile and carry it through UpdateUser rename Login profiles now persist, so deleteUser left an orphaned profile that a recreated user of the same name would inherit, and a rename dropped the profile. DeleteUser now returns DeleteConflict while a login profile exists, as AWS does, and UpdateUser moves the profile to the new name.
This commit is contained in:
1 parent
052da93515
commit
e190f7d340
7 files changed
+685
-16
No files matched your search
+231
@@ -0,0 +1,231 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryController;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
|
||||
/**
|
||||
* Integration tests for the IAM login profile actions via the Query Protocol, covering the full
|
||||
* HTTP stack through {@link AwsQueryController} → {@link IamQueryHandler}.
|
||||
*
|
||||
* <p>Ordered: a login profile is a single per-user value, so these cases share state
|
||||
* deliberately: missing before create, create, duplicate create, get-after-create, update,
|
||||
* update against an unknown user, delete-user conflict, delete, missing after delete,
|
||||
* duplicate delete, delete the user.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class IamLoginProfileIntegrationTest {
|
||||
|
||||
private static final String IAM_CREDENTIAL =
|
||||
"AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request";
|
||||
private static final String USER_NAME = "login-profile-user";
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createTheUser() {
|
||||
given()
|
||||
.formParam("Action", "CreateUser")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void getBeforeAnyCreateIsNoSuchEntity() {
|
||||
given()
|
||||
.formParam("Action", "GetLoginProfile")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void createSetsTheProfile() {
|
||||
given()
|
||||
.formParam("Action", "CreateLoginProfile")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.formParam("Password", "Sup3r$ecret!")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType("application/xml")
|
||||
.body("CreateLoginProfileResponse.CreateLoginProfileResult.LoginProfile.UserName",
|
||||
equalTo(USER_NAME))
|
||||
.body("CreateLoginProfileResponse.CreateLoginProfileResult.LoginProfile.PasswordResetRequired",
|
||||
equalTo("false"))
|
||||
.body("CreateLoginProfileResponse.CreateLoginProfileResult.LoginProfile.CreateDate",
|
||||
notNullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void createAgainIsEntityAlreadyExists() {
|
||||
given()
|
||||
.formParam("Action", "CreateLoginProfile")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.formParam("Password", "AnotherP4ss!")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(409)
|
||||
.body("ErrorResponse.Error.Code", equalTo("EntityAlreadyExists"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void getReturnsTheProfileJustCreated() {
|
||||
given()
|
||||
.formParam("Action", "GetLoginProfile")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("GetLoginProfileResponse.GetLoginProfileResult.LoginProfile.UserName", equalTo(USER_NAME))
|
||||
.body("GetLoginProfileResponse.GetLoginProfileResult.LoginProfile.PasswordResetRequired",
|
||||
equalTo("false"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void updateWithoutUserNameIsValidationError() {
|
||||
given()
|
||||
.formParam("Action", "UpdateLoginProfile")
|
||||
.formParam("Password", "NewP4ssword!")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void updateAgainstAnUnknownUserIsNoSuchEntity() {
|
||||
given()
|
||||
.formParam("Action", "UpdateLoginProfile")
|
||||
.formParam("UserName", "no-such-user")
|
||||
.formParam("PasswordResetRequired", "true")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void updateFlagOnlyLeavesThePasswordInPlace() {
|
||||
given()
|
||||
.formParam("Action", "UpdateLoginProfile")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.formParam("PasswordResetRequired", "true")
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.formParam("Action", "GetLoginProfile")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("GetLoginProfileResponse.GetLoginProfileResult.LoginProfile.PasswordResetRequired",
|
||||
equalTo("true"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void deleteUserWhileProfileExistsIsDeleteConflict() {
|
||||
given()
|
||||
.formParam("Action", "DeleteUser")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(409)
|
||||
.body("ErrorResponse.Error.Code", equalTo("DeleteConflict"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void deleteRemovesTheProfile() {
|
||||
given()
|
||||
.formParam("Action", "DeleteLoginProfile")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void getAfterDeleteIsNoSuchEntity() {
|
||||
given()
|
||||
.formParam("Action", "GetLoginProfile")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
void deleteAgainIsNoSuchEntity() {
|
||||
given()
|
||||
.formParam("Action", "DeleteLoginProfile")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
void deleteTheUser() {
|
||||
given()
|
||||
.formParam("Action", "DeleteUser")
|
||||
.formParam("UserName", USER_NAME)
|
||||
.header("Authorization", IAM_CREDENTIAL)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,13 @@ import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.services.iam.model.AccessKey;
|
||||
import io.github.hectorvent.floci.services.iam.model.AccountPasswordPolicy;
|
||||
import io.github.hectorvent.floci.services.iam.model.CallerContext;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamGroup;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamPolicy;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamRole;
|
||||
import io.github.hectorvent.floci.services.iam.model.IamUser;
|
||||
import io.github.hectorvent.floci.services.iam.model.LoginProfile;
|
||||
import io.github.hectorvent.floci.services.iam.model.OpenIDConnectProvider;
|
||||
import io.github.hectorvent.floci.services.iam.model.InstanceProfile;
|
||||
import io.github.hectorvent.floci.services.iam.model.PolicyVersion;
|
||||
@@ -205,6 +207,157 @@ class IamServiceTest {
|
||||
assertTrue(tags2.containsKey("env"));
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Login Profiles
|
||||
// =========================================================================
|
||||
|
||||
@Test
|
||||
void createGetUpdateAndDeleteLoginProfile() {
|
||||
iamService.createUser("alice", "/");
|
||||
|
||||
LoginProfile created = iamService.createLoginProfile("alice", "Sup3r$ecret!", false);
|
||||
assertEquals("alice", created.getUserName());
|
||||
assertFalse(created.isPasswordResetRequired());
|
||||
|
||||
LoginProfile fetched = iamService.getLoginProfile("alice");
|
||||
assertEquals("Sup3r$ecret!", fetched.getPassword());
|
||||
|
||||
iamService.updateLoginProfile("alice", "NewP4ssword!", true);
|
||||
LoginProfile updated = iamService.getLoginProfile("alice");
|
||||
assertEquals("NewP4ssword!", updated.getPassword());
|
||||
assertTrue(updated.isPasswordResetRequired());
|
||||
|
||||
iamService.deleteLoginProfile("alice");
|
||||
assertThrows(AwsException.class, () -> iamService.getLoginProfile("alice"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createLoginProfileTwiceIsEntityAlreadyExists() {
|
||||
iamService.createUser("alice", "/");
|
||||
iamService.createLoginProfile("alice", "Sup3r$ecret!", false);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.createLoginProfile("alice", "AnotherP4ss!", false));
|
||||
assertEquals("EntityAlreadyExists", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createLoginProfileForUnknownUserIsNoSuchEntity() {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.createLoginProfile("ghost", "Sup3r$ecret!", false));
|
||||
assertEquals("NoSuchEntity", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getLoginProfileForUserWithNoneIsNoSuchEntity() {
|
||||
iamService.createUser("alice", "/");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> iamService.getLoginProfile("alice"));
|
||||
assertEquals("NoSuchEntity", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteLoginProfileForUserWithNoneIsNoSuchEntity() {
|
||||
iamService.createUser("alice", "/");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> iamService.deleteLoginProfile("alice"));
|
||||
assertEquals("NoSuchEntity", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateLoginProfileLeavesAnOmittedFieldUnchanged() {
|
||||
iamService.createUser("alice", "/");
|
||||
iamService.createLoginProfile("alice", "Sup3r$ecret!", true);
|
||||
|
||||
// Only PasswordResetRequired supplied: the stored password must survive untouched.
|
||||
iamService.updateLoginProfile("alice", null, false);
|
||||
LoginProfile afterFlagOnly = iamService.getLoginProfile("alice");
|
||||
assertEquals("Sup3r$ecret!", afterFlagOnly.getPassword());
|
||||
assertFalse(afterFlagOnly.isPasswordResetRequired());
|
||||
|
||||
// Only Password supplied: the reset-required flag must survive untouched.
|
||||
iamService.updateLoginProfile("alice", "NewP4ssword!", null);
|
||||
LoginProfile afterPasswordOnly = iamService.getLoginProfile("alice");
|
||||
assertEquals("NewP4ssword!", afterPasswordOnly.getPassword());
|
||||
assertFalse(afterPasswordOnly.isPasswordResetRequired());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateLoginProfileForUserWithNoneIsNoSuchEntity() {
|
||||
iamService.createUser("alice", "/");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.updateLoginProfile("alice", "NewP4ssword!", null));
|
||||
assertEquals("NoSuchEntity", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createLoginProfileRejectsPasswordViolatingAccountPolicy() {
|
||||
iamService.createUser("alice", "/");
|
||||
AccountPasswordPolicy policy = new AccountPasswordPolicy();
|
||||
policy.setMinimumPasswordLength(12);
|
||||
policy.setRequireSymbols(true);
|
||||
policy.setRequireNumbers(true);
|
||||
iamService.updateAccountPasswordPolicy(policy);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.createLoginProfile("alice", "short", false));
|
||||
assertEquals("PasswordPolicyViolation", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createLoginProfileAcceptsPasswordSatisfyingAccountPolicy() {
|
||||
iamService.createUser("alice", "/");
|
||||
AccountPasswordPolicy policy = new AccountPasswordPolicy();
|
||||
policy.setMinimumPasswordLength(12);
|
||||
policy.setRequireSymbols(true);
|
||||
policy.setRequireNumbers(true);
|
||||
iamService.updateAccountPasswordPolicy(policy);
|
||||
|
||||
LoginProfile profile = iamService.createLoginProfile("alice", "Sup3r$ecret!", false);
|
||||
assertEquals("alice", profile.getUserName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteUserWithLoginProfileIsDeleteConflict() {
|
||||
iamService.createUser("alice", "/");
|
||||
iamService.createLoginProfile("alice", "Sup3r$ecret!", false);
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> iamService.deleteUser("alice"));
|
||||
assertEquals("DeleteConflict", ex.getErrorCode());
|
||||
assertEquals("alice", iamService.getUser("alice").getUserName());
|
||||
|
||||
iamService.deleteLoginProfile("alice");
|
||||
iamService.deleteUser("alice");
|
||||
iamService.createUser("alice", "/");
|
||||
assertThrows(AwsException.class, () -> iamService.getLoginProfile("alice"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void renamingAUserMovesItsLoginProfile() {
|
||||
iamService.createUser("alice", "/");
|
||||
iamService.createLoginProfile("alice", "Sup3r$ecret!", true);
|
||||
|
||||
iamService.updateUser("alice", "alicia", null);
|
||||
|
||||
LoginProfile moved = iamService.getLoginProfile("alicia");
|
||||
assertEquals("alicia", moved.getUserName());
|
||||
assertEquals("Sup3r$ecret!", moved.getPassword());
|
||||
assertTrue(moved.isPasswordResetRequired());
|
||||
iamService.createUser("alice", "/");
|
||||
AwsException ex = assertThrows(AwsException.class, () -> iamService.getLoginProfile("alice"));
|
||||
assertEquals("NoSuchEntity", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createLoginProfileRejectsPasswordOutsideWireCharacterSet() {
|
||||
iamService.createUser("alice", "/");
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> iamService.createLoginProfile("alice", "badpassword", false));
|
||||
assertEquals("ValidationError", ex.getErrorCode());
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Groups
|
||||
// =========================================================================
|
||||
|
||||
Reference in new issue
Block a user