TestDeprecatedConnEvents tests the deprecated connection and disconnection events in the audit logs. These events are no longer created, but need to be returned by the API.
(t *testing.T)
| 510 | // events in the audit logs. These events are no longer created, but need to be |
| 511 | // returned by the API. |
| 512 | func TestDeprecatedConnEvents(t *testing.T) { |
| 513 | t.Parallel() |
| 514 | var ( |
| 515 | ctx = context.Background() |
| 516 | client, _, api = coderdtest.NewWithAPI(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) |
| 517 | user = coderdtest.CreateFirstUser(t, client) |
| 518 | version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, completeWithAgentAndApp()) |
| 519 | template = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) |
| 520 | ) |
| 521 | |
| 522 | coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) |
| 523 | workspace := coderdtest.CreateWorkspace(t, client, template.ID) |
| 524 | workspace.LatestBuild = coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) |
| 525 | |
| 526 | type additionalFields struct { |
| 527 | audit.AdditionalFields |
| 528 | ConnectionType string `json:"connection_type"` |
| 529 | } |
| 530 | |
| 531 | sshFields := additionalFields{ |
| 532 | AdditionalFields: audit.AdditionalFields{ |
| 533 | WorkspaceName: workspace.Name, |
| 534 | BuildNumber: "999", |
| 535 | BuildReason: "initiator", |
| 536 | WorkspaceOwner: workspace.OwnerName, |
| 537 | WorkspaceID: workspace.ID, |
| 538 | }, |
| 539 | ConnectionType: "SSH", |
| 540 | } |
| 541 | |
| 542 | sshFieldsBytes, err := json.Marshal(sshFields) |
| 543 | require.NoError(t, err) |
| 544 | |
| 545 | appFields := audit.AdditionalFields{ |
| 546 | WorkspaceName: workspace.Name, |
| 547 | // Deliberately empty |
| 548 | BuildNumber: "", |
| 549 | BuildReason: "", |
| 550 | WorkspaceOwner: workspace.OwnerName, |
| 551 | WorkspaceID: workspace.ID, |
| 552 | } |
| 553 | |
| 554 | appFieldsBytes, err := json.Marshal(appFields) |
| 555 | require.NoError(t, err) |
| 556 | |
| 557 | dbgen.AuditLog(t, api.Database, database.AuditLog{ |
| 558 | OrganizationID: user.OrganizationID, |
| 559 | Action: database.AuditActionConnect, |
| 560 | ResourceType: database.ResourceTypeWorkspaceAgent, |
| 561 | ResourceID: workspace.LatestBuild.Resources[0].Agents[0].ID, |
| 562 | ResourceTarget: workspace.LatestBuild.Resources[0].Agents[0].Name, |
| 563 | Time: time.Date(2022, 8, 15, 14, 30, 45, 100, time.UTC), // 2022-8-15 14:30:45 |
| 564 | AdditionalFields: sshFieldsBytes, |
| 565 | }) |
| 566 | |
| 567 | dbgen.AuditLog(t, api.Database, database.AuditLog{ |
| 568 | OrganizationID: user.OrganizationID, |
| 569 | Action: database.AuditActionDisconnect, |
nothing calls this directly
no test coverage detected