Auth: Use SHA-1 for generating an ID for External Service Role (#71079)
* Use sha1 (160 bit hash) * Update pkg/services/accesscontrol/database/externalservices.go Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com> * Satisfy linter, clean up --------- Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,9 @@ package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
// #nosec G505 Used only for generating a 160 bit hash, it's not used for security purposes
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
@@ -163,7 +166,7 @@ func TestAccessControlStore_SaveExternalServiceRole(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
errDBSession := s.sql.WithDbSession(ctx, func(sess *db.Session) error {
|
||||
storedRole, err := getRoleByUID(ctx, sess, fmt.Sprintf("externalservice_%s_permissions", tt.runs[i].cmd.ExternalServiceID))
|
||||
storedRole, err := getRoleByUID(ctx, sess, sha1Hash(fmt.Sprintf("externalservice_%s_permissions", tt.runs[i].cmd.ExternalServiceID)))
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, storedRole)
|
||||
require.Equal(t, tt.runs[i].cmd.Global, storedRole.Global(), "Incorrect global state of the role")
|
||||
@@ -300,3 +303,9 @@ func TestAccessControlStore_DeleteExternalServiceRole(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func sha1Hash(text string) string {
|
||||
h := sha1.New()
|
||||
_, _ = h.Write([]byte(text))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user