fix: show the company on login history rows without letting callers set it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
bb39e6b805
commit
f0629192f2
2 files changed
+24
-2
No files matched your search
+2
-2
@@ -1,6 +1,6 @@
|
||||
package com.solvway.services.system.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -17,7 +17,7 @@ public class LoginAudit {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@JsonIgnore
|
||||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) // shown in login history; never set by a caller
|
||||
private Long companyId;
|
||||
|
||||
private String username;
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.solvway.services.system.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/** The company shows in login history, but a caller of the public record endpoint can never set it. */
|
||||
class LoginAuditJsonTest {
|
||||
|
||||
private final ObjectMapper json = new ObjectMapper().findAndRegisterModules();
|
||||
|
||||
@Test
|
||||
void companyIdIsWrittenButNeverRead() throws Exception {
|
||||
LoginAudit a = new LoginAudit();
|
||||
a.setCompanyId(2L);
|
||||
assertThat(json.writeValueAsString(a)).contains("\"companyId\":2");
|
||||
|
||||
LoginAudit in = json.readValue("{\"username\":\"x\",\"companyId\":2}", LoginAudit.class);
|
||||
assertThat(in.getCompanyId()).isNull();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user