MCPcopy Index your code
hub / github.com/coder/coder / TestAuditLogging

Function TestAuditLogging

enterprise/coderd/coderd_test.go:363–414  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

361}
362
363func TestAuditLogging(t *testing.T) {
364 t.Parallel()
365 t.Run("Enabled", func(t *testing.T) {
366 t.Parallel()
367 db, _ := dbtestutil.NewDB(t)
368 _, _, api, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
369 AuditLogging: true,
370 Options: &coderdtest.Options{
371 Auditor: audit.NewAuditor(db, audit.DefaultFilter),
372 },
373 LicenseOptions: &coderdenttest.LicenseOptions{
374 Features: license.Features{
375 codersdk.FeatureAuditLog: 1,
376 },
377 },
378 })
379 db, _ = dbtestutil.NewDB(t)
380 auditor := *api.AGPL.Auditor.Load()
381 ea := audit.NewAuditor(db, audit.DefaultFilter)
382 t.Logf("%T = %T", auditor, ea)
383 assert.EqualValues(t, reflect.ValueOf(ea).Type(), reflect.ValueOf(auditor).Type())
384 })
385 t.Run("Disabled", func(t *testing.T) {
386 t.Parallel()
387 _, _, api, _ := coderdenttest.NewWithAPI(t, &coderdenttest.Options{DontAddLicense: true})
388 auditor := *api.AGPL.Auditor.Load()
389 ea := agplaudit.NewNop()
390 t.Logf("%T = %T", auditor, ea)
391 assert.Equal(t, reflect.ValueOf(ea).Type(), reflect.ValueOf(auditor).Type())
392 })
393 // The AGPL code runs with a fake auditor that doesn't represent the real implementation.
394 // We do a simple test to ensure that basic flows function.
395 t.Run("FullBuild", func(t *testing.T) {
396 t.Parallel()
397 ctx := testutil.Context(t, testutil.WaitLong)
398 client, user := coderdenttest.New(t, &coderdenttest.Options{
399 Options: &coderdtest.Options{
400 IncludeProvisionerDaemon: true,
401 },
402 DontAddLicense: true,
403 })
404 r := setupWorkspaceAgent(t, client, user, 0)
405 conn, err := workspacesdk.New(client).DialAgent(ctx, r.sdkAgent.ID, nil) //nolint:gocritic // RBAC is not the purpose of this test
406 require.NoError(t, err)
407 defer conn.Close()
408 connected := conn.AwaitReachable(ctx)
409 require.True(t, connected)
410 _ = r.agent.Close() // close first so we don't drop error logs from outdated build
411 build := coderdtest.CreateWorkspaceBuild(t, client, r.workspace, database.WorkspaceTransitionStop)
412 coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, build.ID)
413 })
414}
415
416func TestExternalTokenEncryption(t *testing.T) {
417 t.Parallel()

Callers

nothing calls this directly

Calls 15

NewDBFunction · 0.92
NewWithAPIFunction · 0.92
NewAuditorFunction · 0.92
ContextFunction · 0.92
NewFunction · 0.92
NewFunction · 0.92
CreateWorkspaceBuildFunction · 0.92
setupWorkspaceAgentFunction · 0.85
RunMethod · 0.65
LogfMethod · 0.65
TypeMethod · 0.65

Tested by

no test coverage detected