You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.4 KiB

4 years ago
  1. package s3iam
  2. import (
  3. "testing"
  4. "github.com/chrislusf/seaweedfs/weed/pb/iam_pb"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. const (
  8. ACTION_READ = "Read"
  9. ACTION_WRITE = "Write"
  10. ACTION_ADMIN = "Admin"
  11. ACTION_TAGGING = "Tagging"
  12. ACTION_LIST = "List"
  13. )
  14. func TestS3Conf(t *testing.T) {
  15. ifs := &IAMFilerStore{}
  16. s3Conf := &iam_pb.S3ApiConfiguration{
  17. Identities: []*iam_pb.Identity{
  18. {
  19. Name: "some_name",
  20. Credentials: []*iam_pb.Credential{
  21. {
  22. AccessKey: "some_access_key1",
  23. SecretKey: "some_secret_key1",
  24. },
  25. },
  26. Actions: []string{
  27. ACTION_ADMIN,
  28. ACTION_READ,
  29. ACTION_WRITE,
  30. },
  31. },
  32. {
  33. Name: "some_read_only_user",
  34. Credentials: []*iam_pb.Credential{
  35. {
  36. AccessKey: "some_access_key2",
  37. SecretKey: "some_secret_key2",
  38. },
  39. },
  40. Actions: []string{
  41. ACTION_READ,
  42. ACTION_TAGGING,
  43. ACTION_LIST,
  44. },
  45. },
  46. },
  47. }
  48. s3ConfSaved := &iam_pb.S3ApiConfiguration{}
  49. extended := make(map[string][]byte)
  50. _ = ifs.saveIAMConfigToEntryExtended(&extended, s3Conf)
  51. _ = ifs.loadIAMConfigFromEntryExtended(&extended, s3ConfSaved)
  52. assert.Equal(t, "some_name", s3ConfSaved.Identities[0].Name)
  53. assert.Equal(t, "some_read_only_user", s3ConfSaved.Identities[1].Name)
  54. assert.Equal(t, "some_access_key1", s3ConfSaved.Identities[0].Credentials[0].AccessKey)
  55. assert.Equal(t, "some_secret_key2", s3ConfSaved.Identities[1].Credentials[0].SecretKey)
  56. }