s3iam_conf_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package filer
  2. import (
  3. "bytes"
  4. . "github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
  5. "testing"
  6. "github.com/chrislusf/seaweedfs/weed/pb/iam_pb"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestS3Conf(t *testing.T) {
  10. s3Conf := &iam_pb.S3ApiConfiguration{
  11. Identities: []*iam_pb.Identity{
  12. {
  13. Name: "some_name",
  14. Credentials: []*iam_pb.Credential{
  15. {
  16. AccessKey: "some_access_key1",
  17. SecretKey: "some_secret_key1",
  18. },
  19. },
  20. Actions: []string{
  21. ACTION_ADMIN,
  22. ACTION_READ,
  23. ACTION_WRITE,
  24. },
  25. },
  26. {
  27. Name: "some_read_only_user",
  28. Credentials: []*iam_pb.Credential{
  29. {
  30. AccessKey: "some_access_key2",
  31. SecretKey: "some_secret_key2",
  32. },
  33. },
  34. Actions: []string{
  35. ACTION_READ,
  36. ACTION_TAGGING,
  37. ACTION_LIST,
  38. },
  39. },
  40. },
  41. }
  42. var buf bytes.Buffer
  43. err := ProtoToText(&buf, s3Conf)
  44. assert.Equal(t, err, nil)
  45. s3ConfSaved := &iam_pb.S3ApiConfiguration{}
  46. err = ParseS3ConfigurationFromBytes(buf.Bytes(), s3ConfSaved)
  47. assert.Equal(t, err, nil)
  48. assert.Equal(t, "some_name", s3ConfSaved.Identities[0].Name)
  49. assert.Equal(t, "some_read_only_user", s3ConfSaved.Identities[1].Name)
  50. assert.Equal(t, "some_access_key1", s3ConfSaved.Identities[0].Credentials[0].AccessKey)
  51. assert.Equal(t, "some_secret_key2", s3ConfSaved.Identities[1].Credentials[0].SecretKey)
  52. }