Skip to content

Commit 6d817c5

Browse files
slack 19.0: pre backport vitessio#18152 (#638)
* Check `consultopo` loaded >0 credentials Signed-off-by: Tim Vaillancourt <[email protected]> * fix test Signed-off-by: Tim Vaillancourt <[email protected]> * fix test, again Signed-off-by: Tim Vaillancourt <[email protected]> * force CI to run again Signed-off-by: Tim Vaillancourt <[email protected]> --------- Signed-off-by: Tim Vaillancourt <[email protected]>
1 parent f744216 commit 6d817c5

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

go/vt/topo/consultopo/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/spf13/pflag"
3232

3333
"vitess.io/vitess/go/vt/log"
34+
"vitess.io/vitess/go/vt/proto/vtrpc"
3435
"vitess.io/vitess/go/vt/servenv"
3536
"vitess.io/vitess/go/vt/topo"
3637
"vitess.io/vitess/go/vt/vterrors"
@@ -104,6 +105,10 @@ func getClientCreds() (creds map[string]*ClientAuthCred, err error) {
104105
err = vterrors.Wrapf(err, "Error parsing consul_auth_static_file")
105106
return creds, err
106107
}
108+
if len(creds) == 0 {
109+
err = vterrors.New(vtrpc.Code_FAILED_PRECONDITION, "Found no credentials in consul_auth_static_file")
110+
return creds, err
111+
}
107112
return creds, nil
108113
}
109114

go/vt/topo/consultopo/server_flaky_test.go

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ import (
2626
"testing"
2727
"time"
2828

29-
"vitess.io/vitess/go/vt/log"
30-
3129
"github.com/hashicorp/consul/api"
3230

3331
"vitess.io/vitess/go/testfiles"
32+
"vitess.io/vitess/go/vt/log"
3433
"vitess.io/vitess/go/vt/topo"
3534
"vitess.io/vitess/go/vt/topo/test"
3635

@@ -297,25 +296,42 @@ func TestConsulTopoWithAuthFailure(t *testing.T) {
297296

298297
consulAuthClientStaticFile = tmpFile.Name()
299298

300-
jsonConfig := "{\"global\":{\"acl_token\":\"badtoken\"}}"
301-
if err := os.WriteFile(tmpFile.Name(), []byte(jsonConfig), 0600); err != nil {
302-
t.Fatalf("couldn't write temp file: %v", err)
303-
}
299+
// check valid, empty json causes error
300+
{
301+
jsonConfig := "{}"
302+
if err := os.WriteFile(tmpFile.Name(), []byte(jsonConfig), 0600); err != nil {
303+
t.Fatalf("couldn't write temp file: %v", err)
304+
}
304305

305-
// Create the server on the new root.
306-
ts, err := topo.OpenServer("consul", serverAddr, path.Join("globalRoot", topo.GlobalCell))
307-
if err != nil {
308-
t.Fatalf("OpenServer() failed: %v", err)
306+
// Create the server on the new root.
307+
_, err := topo.OpenServer("consul", serverAddr, path.Join("globalRoot", topo.GlobalCell))
308+
if err == nil {
309+
t.Fatal("Expected OpenServer() to return an error due to bad config, got nil")
310+
}
309311
}
310312

311-
// Attempt to Create the CellInfo.
312-
err = ts.CreateCellInfo(context.Background(), test.LocalCellName, &topodatapb.CellInfo{
313-
ServerAddress: serverAddr,
314-
Root: path.Join("globalRoot", test.LocalCellName),
315-
})
313+
// check bad token causes error
314+
{
315+
jsonConfig := "{\"global\":{\"acl_token\":\"badtoken\"}}"
316+
if err := os.WriteFile(tmpFile.Name(), []byte(jsonConfig), 0600); err != nil {
317+
t.Fatalf("couldn't write temp file: %v", err)
318+
}
319+
320+
// Create the server on the new root.
321+
ts, err := topo.OpenServer("consul", serverAddr, path.Join("globalRoot", topo.GlobalCell))
322+
if err != nil {
323+
t.Fatalf("OpenServer() failed: %v", err)
324+
}
325+
326+
// Attempt to Create the CellInfo.
327+
err = ts.CreateCellInfo(context.Background(), test.LocalCellName, &topodatapb.CellInfo{
328+
ServerAddress: serverAddr,
329+
Root: path.Join("globalRoot", test.LocalCellName),
330+
})
316331

317-
want := "Failed request: ACL not found"
318-
if err == nil || err.Error() != want {
319-
t.Errorf("Expected CreateCellInfo to fail: got %v, want %s", err, want)
332+
want := "Failed request: ACL not found"
333+
if err == nil || err.Error() != want {
334+
t.Errorf("Expected CreateCellInfo to fail: got %v, want %s", err, want)
335+
}
320336
}
321337
}

0 commit comments

Comments
 (0)