2017-07-26 18:03:43 +00:00
|
|
|
package token
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2017-08-03 22:39:31 +00:00
|
|
|
func TestStore_RegularTokens(t *testing.T) {
|
2017-07-26 18:03:43 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-08-03 22:39:31 +00:00
|
|
|
type tokens struct {
|
|
|
|
user, agent, repl string
|
|
|
|
}
|
|
|
|
|
2017-07-26 18:03:43 +00:00
|
|
|
tests := []struct {
|
2017-08-03 22:39:31 +00:00
|
|
|
name string
|
|
|
|
set, want tokens
|
2017-07-26 18:03:43 +00:00
|
|
|
}{
|
2017-08-03 22:39:31 +00:00
|
|
|
{
|
|
|
|
name: "set user",
|
|
|
|
set: tokens{user: "U"},
|
|
|
|
want: tokens{user: "U", agent: "U"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set agent",
|
|
|
|
set: tokens{agent: "A"},
|
|
|
|
want: tokens{agent: "A"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set user and agent",
|
|
|
|
set: tokens{agent: "A", user: "U"},
|
|
|
|
want: tokens{agent: "A", user: "U"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set repl",
|
|
|
|
set: tokens{repl: "R"},
|
|
|
|
want: tokens{repl: "R"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "set all",
|
|
|
|
set: tokens{user: "U", agent: "A", repl: "R"},
|
|
|
|
want: tokens{user: "U", agent: "A", repl: "R"},
|
|
|
|
},
|
2017-07-26 18:03:43 +00:00
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
2017-08-03 22:39:31 +00:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
s := new(Store)
|
|
|
|
s.UpdateUserToken(tt.set.user)
|
|
|
|
s.UpdateAgentToken(tt.set.agent)
|
|
|
|
s.UpdateACLReplicationToken(tt.set.repl)
|
|
|
|
if got, want := s.UserToken(), tt.want.user; got != want {
|
|
|
|
t.Fatalf("got token %q want %q", got, want)
|
|
|
|
}
|
|
|
|
if got, want := s.AgentToken(), tt.want.agent; got != want {
|
|
|
|
t.Fatalf("got token %q want %q", got, want)
|
|
|
|
}
|
|
|
|
if got, want := s.ACLReplicationToken(), tt.want.repl; got != want {
|
|
|
|
t.Fatalf("got token %q want %q", got, want)
|
|
|
|
}
|
|
|
|
})
|
2017-07-26 18:03:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStore_AgentMasterToken(t *testing.T) {
|
|
|
|
t.Parallel()
|
2017-08-03 22:39:31 +00:00
|
|
|
s := new(Store)
|
2017-07-26 18:03:43 +00:00
|
|
|
|
|
|
|
verify := func(want bool, toks ...string) {
|
|
|
|
for _, tok := range toks {
|
2017-08-03 22:39:31 +00:00
|
|
|
if got := s.IsAgentMasterToken(tok); got != want {
|
2017-07-26 18:03:43 +00:00
|
|
|
t.Fatalf("token %q got %v want %v", tok, got, want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
verify(false, "", "nope")
|
|
|
|
|
2017-08-03 22:39:31 +00:00
|
|
|
s.UpdateAgentMasterToken("master")
|
2017-07-26 18:03:43 +00:00
|
|
|
verify(true, "master")
|
|
|
|
verify(false, "", "nope")
|
|
|
|
|
2017-08-03 22:39:31 +00:00
|
|
|
s.UpdateAgentMasterToken("another")
|
2017-07-26 18:03:43 +00:00
|
|
|
verify(true, "another")
|
|
|
|
verify(false, "", "nope", "master")
|
|
|
|
|
2017-08-03 22:39:31 +00:00
|
|
|
s.UpdateAgentMasterToken("")
|
2017-07-26 18:03:43 +00:00
|
|
|
verify(false, "", "nope", "master", "another")
|
|
|
|
}
|