MCPcopy
hub / github.com/seaweedfs/seaweedfs / testPolicyOperations

Function testPolicyOperations

weed/credential/test/policy_test.go:31–135  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, credentialManager *credential.CredentialManager)

Source from the content-addressed store, hash-verified

29}
30
31func testPolicyOperations(t *testing.T, ctx context.Context, credentialManager *credential.CredentialManager) {
32 store := credentialManager.GetStore()
33
34 // Cast to memory store to access policy methods
35 memoryStore, ok := store.(*memory.MemoryStore)
36 if !ok {
37 t.Skip("Store is not a memory store")
38 }
39
40 // Test GetPolicies (should be empty initially)
41 policies, err := memoryStore.GetPolicies(ctx)
42 if err != nil {
43 t.Fatalf("Failed to get policies: %v", err)
44 }
45 if len(policies) != 0 {
46 t.Errorf("Expected 0 policies, got %d", len(policies))
47 }
48
49 // Test CreatePolicy
50 testPolicy := policy_engine.PolicyDocument{
51 Version: "2012-10-17",
52 Statement: []policy_engine.PolicyStatement{
53 {
54 Effect: policy_engine.PolicyEffectAllow,
55 Action: policy_engine.NewStringOrStringSlice("s3:GetObject"),
56 Resource: policy_engine.NewStringOrStringSlicePtr("arn:aws:s3:::test-bucket/*"),
57 },
58 },
59 }
60
61 err = memoryStore.CreatePolicy(ctx, "test-policy", testPolicy)
62 if err != nil {
63 t.Fatalf("Failed to create policy: %v", err)
64 }
65
66 // Test GetPolicies (should have 1 policy now)
67 policies, err = memoryStore.GetPolicies(ctx)
68 if err != nil {
69 t.Fatalf("Failed to get policies: %v", err)
70 }
71 if len(policies) != 1 {
72 t.Errorf("Expected 1 policy, got %d", len(policies))
73 }
74
75 // Verify policy content
76 policy, exists := policies["test-policy"]
77 if !exists {
78 t.Error("test-policy not found")
79 }
80 if policy.Version != "2012-10-17" {
81 t.Errorf("Expected policy version '2012-10-17', got '%s'", policy.Version)
82 }
83 if len(policy.Statement) != 1 {
84 t.Errorf("Expected 1 statement, got %d", len(policy.Statement))
85 }
86
87 // Test UpdatePolicy
88 updatedPolicy := policy_engine.PolicyDocument{

Callers 1

TestPolicyManagementFunction · 0.85

Calls 9

NewStringOrStringSliceFunction · 0.92
GetPoliciesMethod · 0.65
CreatePolicyMethod · 0.65
ErrorMethod · 0.65
UpdatePolicyMethod · 0.65
DeletePolicyMethod · 0.65
GetStoreMethod · 0.45
StringsMethod · 0.45

Tested by

no test coverage detected