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.

65 lines
1.5 KiB

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