Skip to content

Commit

Permalink
fixup test setup for signing requests which must be authenticated
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross committed Oct 12, 2023
1 parent b07a322 commit 262324c
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/widmgr/widmgr_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestWIDMgr(t *testing.T) {
t.Cleanup(ta.Shutdown)

mgr := widmgr.NewSigner(widmgr.SignerConfig{
NodeSecret: uuid.Generate(), // not checked when ACLs disabled
NodeSecret: ta.Client().Node().SecretID,
Region: "global",
RPC: ta,
})
Expand Down
2 changes: 1 addition & 1 deletion command/agent/event_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestHTTP_Alloc_Port_Response(t *testing.T) {
ci.Parallel(t)

httpTest(t, nil, func(srv *TestAgent) {
client := srv.Client()
client := srv.APIClient()
defer srv.Shutdown()
defer client.Close()

Expand Down
2 changes: 1 addition & 1 deletion command/agent/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ func testServer(t *testing.T, runClient bool, cb func(*Config)) (*TestAgent, *ap
})
t.Cleanup(a.Shutdown)

c := a.Client()
c := a.APIClient()
return a, c, a.HTTPAddr()
}
2 changes: 1 addition & 1 deletion command/agent/testagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func (a *TestAgent) HTTPAddr() string {
return proto + a.Server.Addr
}

func (a *TestAgent) Client() *api.Client {
func (a *TestAgent) APIClient() *api.Client {
conf := api.DefaultConfig()
conf.Address = a.HTTPAddr()
c, err := api.NewClient(conf)
Expand Down
2 changes: 1 addition & 1 deletion command/operator_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ func testServerWithoutLeader(t *testing.T, runClient bool, cb func(*agent.Config
})
t.Cleanup(func() { a.Shutdown() })

c := a.Client()
c := a.APIClient()
return a, c, a.HTTPAddr()
}

Expand Down
6 changes: 3 additions & 3 deletions command/operator_scheduler_set_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestOperatorSchedulerSetConfig_Run(t *testing.T) {
ui := cli.NewMockUi()
c := &OperatorSchedulerSetConfig{Meta: Meta{Ui: ui}}

bootstrappedConfig, _, err := srv.Client().Operator().SchedulerGetConfiguration(nil)
bootstrappedConfig, _, err := srv.APIClient().Operator().SchedulerGetConfiguration(nil)
require.NoError(t, err)
require.NotEmpty(t, bootstrappedConfig.SchedulerConfig)

Expand All @@ -34,7 +34,7 @@ func TestOperatorSchedulerSetConfig_Run(t *testing.T) {

// Read the configuration again and test that nothing has changed which
// ensures our empty flags are working correctly.
nonModifiedConfig, _, err := srv.Client().Operator().SchedulerGetConfiguration(nil)
nonModifiedConfig, _, err := srv.APIClient().Operator().SchedulerGetConfiguration(nil)
require.NoError(t, err)
schedulerConfigEquals(t, bootstrappedConfig.SchedulerConfig, nonModifiedConfig.SchedulerConfig)

Expand All @@ -56,7 +56,7 @@ func TestOperatorSchedulerSetConfig_Run(t *testing.T) {
s := ui.OutputWriter.String()
require.Contains(t, s, "Scheduler configuration updated!")

modifiedConfig, _, err := srv.Client().Operator().SchedulerGetConfiguration(nil)
modifiedConfig, _, err := srv.APIClient().Operator().SchedulerGetConfiguration(nil)
require.NoError(t, err)
schedulerConfigEquals(t, &api.SchedulerConfiguration{
SchedulerAlgorithm: "spread",
Expand Down
4 changes: 2 additions & 2 deletions command/testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func testServer(t *testing.T, runClient bool, cb func(*agent.Config)) (*agent.Te
})
t.Cleanup(a.Shutdown)

c := a.Client()
c := a.APIClient()
return a, c, a.HTTPAddr()
}

Expand All @@ -46,7 +46,7 @@ func testClient(t *testing.T, name string, cb func(*agent.Config)) (*agent.TestA
})
t.Cleanup(a.Shutdown)

c := a.Client()
c := a.APIClient()
t.Logf("Waiting for client %s to join server(s) %s", name, a.GetConfig().Client.Servers)
testutil.WaitForClient(t, a.Agent.RPC, a.Agent.Client().NodeID(), a.Agent.Client().Region())

Expand Down
4 changes: 2 additions & 2 deletions command/var_lock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestVarLockCommand_Good(t *testing.T) {
code := cmd.Run([]string{"-address=" + url, "test/var/shell", "touch ", filePath})
require.Equal(t, 0, code, "expected exit 0, got: %d; %v", code, ui.ErrorWriter.String())

sv, _, err := srv.Client().Variables().Peek("test/var/shell", nil)
sv, _, err := srv.APIClient().Variables().Peek("test/var/shell", nil)
must.NoError(t, err)

must.NotNil(t, sv)
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestVarLockCommand_Good_NoShell(t *testing.T) {
code := cmd.Run([]string{"-address=" + url, "-shell=false", "test/var/noShell", "touch", filePath})
require.Zero(t, 0, code)

sv, _, err := srv.Client().Variables().Peek("test/var/noShell", nil)
sv, _, err := srv.APIClient().Variables().Peek("test/var/noShell", nil)
must.NoError(t, err)

must.NotNil(t, sv)
Expand Down
8 changes: 8 additions & 0 deletions nomad/alloc_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1692,11 +1692,15 @@ func TestAlloc_SignIdentities_Bad(t *testing.T) {
codec := rpcClient(t, s1)
testutil.WaitForLeader(t, s1.RPC)

node := mock.Node()
must.NoError(t, s1.fsm.State().UpsertNode(structs.MsgTypeTestSetup, 100, node))

req := &structs.AllocIdentitiesRequest{
QueryOptions: structs.QueryOptions{
Region: "global",
Namespace: structs.DefaultNamespace,
AllowStale: true,
AuthToken: node.SecretID,
},
}
var resp structs.AllocIdentitiesResponse
Expand Down Expand Up @@ -1779,6 +1783,9 @@ func TestAlloc_SignIdentities_Blocking(t *testing.T) {
testutil.WaitForLeader(t, s1.RPC)
state := s1.fsm.State()

node := mock.Node()
must.NoError(t, s1.fsm.State().UpsertNode(structs.MsgTypeTestSetup, 100, node))

// Create the alloc we're going to query for, but don't insert it yet. This
// simulates querying a slow follower or a restoring server.
alloc := mock.Alloc()
Expand Down Expand Up @@ -1819,6 +1826,7 @@ func TestAlloc_SignIdentities_Blocking(t *testing.T) {
AllowStale: true,
MinQueryIndex: 1999,
MaxQueryTime: 10 * time.Second,
AuthToken: node.SecretID,
},
}
var resp structs.AllocIdentitiesResponse
Expand Down

0 comments on commit 262324c

Please sign in to comment.