(t *testing.T)
| 60 | } |
| 61 | |
| 62 | func TestDoSync(t *testing.T) { |
| 63 | e, closer := testEnforcer(t) |
| 64 | defer closer.Close() |
| 65 | |
| 66 | // Clear any existing policy |
| 67 | e.ClearPolicy() |
| 68 | |
| 69 | policiesM := map[Role][]*Policy{ |
| 70 | "foo": { |
| 71 | PolicyWorkflowContractList, |
| 72 | PolicyWorkflowContractRead, |
| 73 | }, "bar": { |
| 74 | PolicyArtifactDownload, |
| 75 | }, |
| 76 | } |
| 77 | |
| 78 | // load custom policies |
| 79 | err := syncRBACRoles(e, &Config{RolesMap: policiesM}) |
| 80 | assert.NoError(t, err) |
| 81 | got, err := e.GetPolicy() |
| 82 | assert.NoError(t, err) |
| 83 | assert.Len(t, got, 3) |
| 84 | |
| 85 | // update stored map removing one item of one role |
| 86 | policiesM = map[Role][]*Policy{ |
| 87 | "foo": { |
| 88 | PolicyWorkflowContractList, |
| 89 | }, |
| 90 | "bar": { |
| 91 | PolicyArtifactDownload, |
| 92 | }, |
| 93 | } |
| 94 | |
| 95 | err = syncRBACRoles(e, &Config{RolesMap: policiesM}) |
| 96 | assert.NoError(t, err) |
| 97 | got, err = e.GetPolicy() |
| 98 | assert.NoError(t, err) |
| 99 | assert.Len(t, got, 2) |
| 100 | |
| 101 | // or deleting a whole section |
| 102 | policiesM = map[Role][]*Policy{ |
| 103 | "bar": { |
| 104 | PolicyArtifactDownload, |
| 105 | }, |
| 106 | } |
| 107 | |
| 108 | err = syncRBACRoles(e, &Config{RolesMap: policiesM}) |
| 109 | assert.NoError(t, err) |
| 110 | got, err = e.GetPolicy() |
| 111 | assert.NoError(t, err) |
| 112 | assert.Len(t, got, 1) |
| 113 | |
| 114 | // replace policy for a role - old policies are removed and new ones added |
| 115 | policiesM = map[Role][]*Policy{ |
| 116 | "bar": { |
| 117 | PolicyAttachedIntegrationDetach, |
| 118 | }, |
| 119 | } |
nothing calls this directly
no test coverage detected