MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / TestUserEvents

Function TestUserEvents

app/controlplane/pkg/auditor/events/user_test.go:34–114  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32)
33
34func TestUserEvents(t *testing.T) {
35 userUUID, err := uuid.Parse("1089bb36-e27b-428b-8009-d015c8737c54")
36 require.NoError(t, err)
37 orgUUID, err := uuid.Parse("1089bb36-e27b-428b-8009-d015c8737c54")
38 require.NoError(t, err)
39 const testEmail = "john@cyberdyne.io"
40
41 tests := []struct {
42 name string
43 event auditor.LogEntry
44 expected string
45 }{
46 {
47 name: "User signs up",
48 event: &events.UserSignedUp{
49 UserBase: &events.UserBase{
50 UserID: uuidPtr(userUUID),
51 Email: testEmail,
52 Source: "oidc",
53 },
54 },
55 expected: "testdata/users/user_signs_up.json",
56 },
57 {
58 name: "User logs in",
59 event: &events.UserLoggedIn{
60 UserBase: &events.UserBase{
61 UserID: uuidPtr(userUUID),
62 Email: testEmail,
63 Source: "oidc",
64 },
65 LoggedIn: time.Date(2024, time.January, 1, 0, 0, 0, 0, time.UTC),
66 },
67 expected: "testdata/users/user_logs_in.json",
68 },
69 {
70 name: "User role changed",
71 event: &events.UserRoleChanged{
72 UserBase: &events.UserBase{
73 UserID: uuidPtr(userUUID),
74 Email: testEmail,
75 SSOGroups: []string{"group1", "group2"},
76 },
77 OldRole: string(authz.RoleOwner),
78 NewRole: string(authz.RoleOrgMember),
79 },
80 expected: "testdata/users/user_role_changed.json",
81 },
82 }
83
84 for _, tt := range tests {
85 t.Run(tt.name, func(t *testing.T) {
86 opts := []auditor.GeneratorOption{
87 auditor.WithActor(auditor.ActorTypeUser, userUUID, testEmail, testName),
88 auditor.WithOrgID(orgUUID),
89 }
90
91 eventPayload, err := auditor.GenerateAuditEvent(tt.event, opts...)

Callers

nothing calls this directly

Calls 6

WithActorFunction · 0.92
WithOrgIDFunction · 0.92
GenerateAuditEventFunction · 0.92
uuidPtrFunction · 0.85
ParseMethod · 0.80
RunMethod · 0.45

Tested by

no test coverage detected