auth_credentials_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package s3api
  2. import (
  3. . "github.com/chrislusf/seaweedfs/weed/s3api/s3_constants"
  4. "testing"
  5. "github.com/golang/protobuf/jsonpb"
  6. "github.com/chrislusf/seaweedfs/weed/pb/iam_pb"
  7. )
  8. func TestIdentityListFileFormat(t *testing.T) {
  9. s3ApiConfiguration := &iam_pb.S3ApiConfiguration{}
  10. identity1 := &iam_pb.Identity{
  11. Name: "some_name",
  12. Credentials: []*iam_pb.Credential{
  13. {
  14. AccessKey: "some_access_key1",
  15. SecretKey: "some_secret_key2",
  16. },
  17. },
  18. Actions: []string{
  19. ACTION_ADMIN,
  20. ACTION_READ,
  21. ACTION_WRITE,
  22. },
  23. }
  24. identity2 := &iam_pb.Identity{
  25. Name: "some_read_only_user",
  26. Credentials: []*iam_pb.Credential{
  27. {
  28. AccessKey: "some_access_key1",
  29. SecretKey: "some_secret_key1",
  30. },
  31. },
  32. Actions: []string{
  33. ACTION_READ,
  34. },
  35. }
  36. identity3 := &iam_pb.Identity{
  37. Name: "some_normal_user",
  38. Credentials: []*iam_pb.Credential{
  39. {
  40. AccessKey: "some_access_key2",
  41. SecretKey: "some_secret_key2",
  42. },
  43. },
  44. Actions: []string{
  45. ACTION_READ,
  46. ACTION_WRITE,
  47. },
  48. }
  49. s3ApiConfiguration.Identities = append(s3ApiConfiguration.Identities, identity1)
  50. s3ApiConfiguration.Identities = append(s3ApiConfiguration.Identities, identity2)
  51. s3ApiConfiguration.Identities = append(s3ApiConfiguration.Identities, identity3)
  52. m := jsonpb.Marshaler{
  53. EmitDefaults: true,
  54. Indent: " ",
  55. }
  56. text, _ := m.MarshalToString(s3ApiConfiguration)
  57. println(text)
  58. }