auth_credentials_test.go 1.3 KB

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