mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(audit): audit login/logout for new 3rd-party auth (#6733)
* fix(audit): audit login/logout for new 3rd-party auth * no longer auditing unknown users
This commit is contained in:
@@ -4,7 +4,6 @@ import {
|
||||
MockWorkspaceCreateAuditLogForDifferentOwner,
|
||||
MockAuditLogSuccessfulLogin,
|
||||
MockAuditLogUnsuccessfulLoginKnownUser,
|
||||
MockAuditLogUnsuccessfulLoginUnknownUser,
|
||||
} from "testHelpers/entities"
|
||||
import { AuditLogDescription } from "./AuditLogDescription"
|
||||
import { AuditLogRow } from "../AuditLogRow"
|
||||
@@ -101,25 +100,6 @@ describe("AuditLogDescription", () => {
|
||||
),
|
||||
).toBeInTheDocument()
|
||||
|
||||
const statusPill = screen.getByRole("status")
|
||||
expect(statusPill).toHaveTextContent("401")
|
||||
})
|
||||
it("renders the correct string for unsuccessful login for an unknown user", async () => {
|
||||
render(<AuditLogRow auditLog={MockAuditLogUnsuccessfulLoginUnknownUser} />)
|
||||
|
||||
expect(
|
||||
screen.getByText(
|
||||
t("auditLog:table.logRow.description.unlinkedAuditDescription", {
|
||||
truncatedDescription: "an unknown user logged in",
|
||||
target: "",
|
||||
onBehalfOf: undefined,
|
||||
})
|
||||
.replace(/<[^>]*>/g, " ")
|
||||
.replace(/\s{2,}/g, " ")
|
||||
.trim(),
|
||||
),
|
||||
).toBeInTheDocument()
|
||||
|
||||
const statusPill = screen.getByRole("status")
|
||||
expect(statusPill).toHaveTextContent("401")
|
||||
})
|
||||
|
||||
@@ -11,7 +11,7 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
|
||||
const { t } = useTranslation("auditLog")
|
||||
|
||||
let target = auditLog.resource_target.trim()
|
||||
const user = auditLog.user ? auditLog.user.username.trim() : "an unknown user"
|
||||
const user = auditLog.user?.username.trim()
|
||||
|
||||
if (auditLog.resource_type === "workspace_build") {
|
||||
return <BuildAuditDescription auditLog={auditLog} />
|
||||
@@ -30,7 +30,7 @@ export const AuditLogDescription: FC<{ auditLog: AuditLog }> = ({
|
||||
const onBehalfOf =
|
||||
auditLog.additional_fields.workspace_owner &&
|
||||
auditLog.additional_fields.workspace_owner !== "unknown" &&
|
||||
auditLog.additional_fields.workspace_owner !== auditLog.user?.username
|
||||
auditLog.additional_fields.workspace_owner.trim() !== user
|
||||
? `on behalf of ${auditLog.additional_fields.workspace_owner}`
|
||||
: ""
|
||||
|
||||
|
||||
@@ -1384,12 +1384,6 @@ export const MockAuditLogUnsuccessfulLoginKnownUser: TypesGen.AuditLog = {
|
||||
status_code: 401,
|
||||
}
|
||||
|
||||
export const MockAuditLogUnsuccessfulLoginUnknownUser: TypesGen.AuditLog = {
|
||||
...MockAuditLogSuccessfulLogin,
|
||||
status_code: 401,
|
||||
user: undefined,
|
||||
}
|
||||
|
||||
export const MockWorkspaceQuota: TypesGen.WorkspaceQuota = {
|
||||
credits_consumed: 0,
|
||||
budget: 100,
|
||||
|
||||
Reference in New Issue
Block a user