(t *testing.T)
| 732 | } |
| 733 | |
| 734 | func TestWorkspaceAgentConnectRPC(t *testing.T) { |
| 735 | t.Parallel() |
| 736 | |
| 737 | t.Run("Connect", func(t *testing.T) { |
| 738 | t.Parallel() |
| 739 | |
| 740 | for _, tc := range []struct { |
| 741 | name string |
| 742 | apiKeyScope rbac.ScopeName |
| 743 | }{ |
| 744 | { |
| 745 | name: "empty (backwards compat)", |
| 746 | apiKeyScope: "", |
| 747 | }, |
| 748 | { |
| 749 | name: "all", |
| 750 | apiKeyScope: rbac.ScopeAll, |
| 751 | }, |
| 752 | { |
| 753 | name: "no_user_data", |
| 754 | apiKeyScope: rbac.ScopeNoUserData, |
| 755 | }, |
| 756 | { |
| 757 | name: "application_connect", |
| 758 | apiKeyScope: rbac.ScopeApplicationConnect, |
| 759 | }, |
| 760 | } { |
| 761 | t.Run(tc.name, func(t *testing.T) { |
| 762 | client, db := coderdtest.NewWithDatabase(t, nil) |
| 763 | user := coderdtest.CreateFirstUser(t, client) |
| 764 | r := dbfake.WorkspaceBuild(t, db, database.WorkspaceTable{ |
| 765 | OrganizationID: user.OrganizationID, |
| 766 | OwnerID: user.UserID, |
| 767 | }).WithAgent(func(agents []*proto.Agent) []*proto.Agent { |
| 768 | for _, agent := range agents { |
| 769 | agent.ApiKeyScope = string(tc.apiKeyScope) |
| 770 | } |
| 771 | |
| 772 | return agents |
| 773 | }).Do() |
| 774 | _ = agenttest.New(t, client.URL, r.AgentToken) |
| 775 | resources := coderdtest.NewWorkspaceAgentWaiter(t, client, r.Workspace.ID).AgentNames([]string{}).Wait() |
| 776 | |
| 777 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 778 | defer cancel() |
| 779 | |
| 780 | conn, err := workspacesdk.New(client). |
| 781 | DialAgent(ctx, resources[0].Agents[0].ID, nil) |
| 782 | require.NoError(t, err) |
| 783 | defer func() { |
| 784 | _ = conn.Close() |
| 785 | }() |
| 786 | conn.AwaitReachable(ctx) |
| 787 | }) |
| 788 | } |
| 789 | }) |
| 790 | |
| 791 | t.Run("FailNonLatestBuild", func(t *testing.T) { |
nothing calls this directly
no test coverage detected