Skip to content

Commit

Permalink
Merge pull request #821 from rithujohn191/cherry-pick
Browse files Browse the repository at this point in the history
storage/kubernetes: fix hash initialization bug
  • Loading branch information
ericchiang authored Feb 24, 2017
2 parents f8aec4c + 2cfcdfb commit 565805b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions storage/kubernetes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ func idToName(s string, h func() hash.Hash) string {
}

func offlineTokenName(userID string, connID string, h func() hash.Hash) string {
h().Write([]byte(userID))
h().Write([]byte(connID))
return strings.TrimRight(encoding.EncodeToString(h().Sum(nil)), "=")
hash := h()
hash.Write([]byte(userID))
hash.Write([]byte(connID))
return strings.TrimRight(encoding.EncodeToString(hash.Sum(nil)), "=")
}

func (c *client) urlFor(apiVersion, namespace, resource, name string) string {
Expand Down
13 changes: 13 additions & 0 deletions storage/kubernetes/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ func TestIDToName(t *testing.T) {
wg.Wait()
}

func TestOfflineTokenName(t *testing.T) {
h := func() hash.Hash { return fnv.New64() }

userID1 := "john"
userID2 := "jane"

id1 := offlineTokenName(userID1, "local", h)
id2 := offlineTokenName(userID2, "local", h)
if id1 == id2 {
t.Errorf("expected offlineTokenName to produce different hashes")
}
}

func TestNamespaceFromServiceAccountJWT(t *testing.T) {
namespace, err := namespaceFromServiceAccountJWT(serviceAccountToken)
if err != nil {
Expand Down

0 comments on commit 565805b

Please sign in to comment.