|
| 1 | +package authorization_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/go-crypt/crypt/algorithm" |
| 7 | + "github.com/influxdata/influxdb/v2/authorization" |
| 8 | + influxdb2_algo "github.com/influxdata/influxdb/v2/pkg/crypt/algorithm/influxdb2" |
| 9 | + "github.com/stretchr/testify/require" |
| 10 | +) |
| 11 | + |
| 12 | +func Test_NewAuthorizationHasher_EmptyDecoderVariants(t *testing.T) { |
| 13 | + hasher, err := authorization.NewAuthorizationHasher( |
| 14 | + authorization.WithDecoderVariants([]influxdb2_algo.Variant{}), |
| 15 | + ) |
| 16 | + |
| 17 | + require.ErrorIs(t, err, authorization.ErrNoDecoders) |
| 18 | + require.Nil(t, hasher) |
| 19 | +} |
| 20 | + |
| 21 | +func TestNewAuthorizationHasher_WithInvalidDecoderVariant(t *testing.T) { |
| 22 | + // Test that using an invalid decoder variant returns an error |
| 23 | + hasher, err := authorization.NewAuthorizationHasher( |
| 24 | + authorization.WithDecoderVariants([]influxdb2_algo.Variant{ |
| 25 | + influxdb2_algo.Variant(-1), // Invalid variant |
| 26 | + }), |
| 27 | + ) |
| 28 | + |
| 29 | + // Should return an error and nil hasher |
| 30 | + require.ErrorIs(t, err, algorithm.ErrParameterInvalid) |
| 31 | + require.Contains(t, err.Error(), "registering variant") |
| 32 | + require.Nil(t, hasher) |
| 33 | +} |
| 34 | + |
| 35 | +func TestNewAuthorizationHasher_WithHasherVariantInvalid(t *testing.T) { |
| 36 | + // Test that using VariantNone returns an error |
| 37 | + hasher, err := authorization.NewAuthorizationHasher( |
| 38 | + authorization.WithHasherVariant(influxdb2_algo.Variant(-1)), |
| 39 | + ) |
| 40 | + |
| 41 | + // Should return an error and nil hasher |
| 42 | + require.ErrorIs(t, err, algorithm.ErrParameterInvalid) |
| 43 | + require.ErrorContains(t, err, "creating hasher") |
| 44 | + require.Nil(t, hasher) |
| 45 | +} |
0 commit comments