Merge pull request #817 from ericchiang/fix-hash-bug
storage/kubernetes: fix hash initialization bug
This commit is contained in:
commit
cd93930934
@ -72,9 +72,10 @@ func idToName(s string, h func() hash.Hash) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func offlineTokenName(userID string, connID string, h func() hash.Hash) string {
|
func offlineTokenName(userID string, connID string, h func() hash.Hash) string {
|
||||||
h().Write([]byte(userID))
|
hash := h()
|
||||||
h().Write([]byte(connID))
|
hash.Write([]byte(userID))
|
||||||
return strings.TrimRight(encoding.EncodeToString(h().Sum(nil)), "=")
|
hash.Write([]byte(connID))
|
||||||
|
return strings.TrimRight(encoding.EncodeToString(hash.Sum(nil)), "=")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *client) urlFor(apiVersion, namespace, resource, name string) string {
|
func (c *client) urlFor(apiVersion, namespace, resource, name string) string {
|
||||||
|
@ -29,6 +29,19 @@ func TestIDToName(t *testing.T) {
|
|||||||
wg.Wait()
|
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) {
|
func TestNamespaceFromServiceAccountJWT(t *testing.T) {
|
||||||
namespace, err := namespaceFromServiceAccountJWT(serviceAccountToken)
|
namespace, err := namespaceFromServiceAccountJWT(serviceAccountToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user