|
26 | 26 | from superset.models.dashboard import Dashboard
|
27 | 27 | from superset.utils.urls import get_url_host
|
28 | 28 | from superset.utils import json
|
| 29 | +from tests.integration_tests.conftest import with_config |
29 | 30 | from tests.integration_tests.base_tests import SupersetTestCase
|
30 | 31 | from tests.integration_tests.constants import ADMIN_USERNAME, GAMMA_USERNAME
|
31 | 32 | from tests.integration_tests.fixtures.birth_names_dashboard import (
|
@@ -135,3 +136,64 @@ def test_post_guest_token_bad_resources(self):
|
135 | 136 | )
|
136 | 137 |
|
137 | 138 | self.assert400(response)
|
| 139 | + |
| 140 | + |
| 141 | +class TestSecurityRolesApi(SupersetTestCase): |
| 142 | + uri = "api/v1/security/roles/" # noqa: F541 |
| 143 | + |
| 144 | + @with_config({"FAB_ADD_SECURITY_API": True}) |
| 145 | + def test_get_security_roles_admin(self): |
| 146 | + """ |
| 147 | + Security API: Admin should be able to get roles |
| 148 | + """ |
| 149 | + self.login(ADMIN_USERNAME) |
| 150 | + response = self.client.get(self.uri) |
| 151 | + self.assert200(response) |
| 152 | + |
| 153 | + @with_config({"FAB_ADD_SECURITY_API": True}) |
| 154 | + def test_get_security_roles_gamma(self): |
| 155 | + """ |
| 156 | + Security API: Gamma should not be able to get roles |
| 157 | + """ |
| 158 | + self.login(GAMMA_USERNAME) |
| 159 | + response = self.client.get(self.uri) |
| 160 | + self.assert403(response) |
| 161 | + |
| 162 | + @with_config({"FAB_ADD_SECURITY_API": True}) |
| 163 | + def test_post_security_roles_gamma(self): |
| 164 | + """ |
| 165 | + Security API: Gamma should not be able to create roles |
| 166 | + """ |
| 167 | + self.login(GAMMA_USERNAME) |
| 168 | + response = self.client.post( |
| 169 | + self.uri, |
| 170 | + data=json.dumps({"name": "new_role"}), |
| 171 | + content_type="application/json", |
| 172 | + ) |
| 173 | + self.assert403(response) |
| 174 | + |
| 175 | + @with_config({"FAB_ADD_SECURITY_API": True}) |
| 176 | + def test_put_security_roles_gamma(self): |
| 177 | + """ |
| 178 | + Security API: Gamma shouldnt be able to update roles |
| 179 | + """ |
| 180 | + self.login(GAMMA_USERNAME) |
| 181 | + response = self.client.put( |
| 182 | + f"{self.uri}1", |
| 183 | + data=json.dumps({"name": "new_role"}), |
| 184 | + content_type="application/json", |
| 185 | + ) |
| 186 | + self.assert403(response) |
| 187 | + |
| 188 | + @with_config({"FAB_ADD_SECURITY_API": True}) |
| 189 | + def test_delete_security_roles_gamma(self): |
| 190 | + """ |
| 191 | + Security API: Gamma shouldnt be able to delete roles |
| 192 | + """ |
| 193 | + self.login(GAMMA_USERNAME) |
| 194 | + response = self.client.delete( |
| 195 | + f"{self.uri}1", |
| 196 | + data=json.dumps({"name": "new_role"}), |
| 197 | + content_type="application/json", |
| 198 | + ) |
| 199 | + self.assert403(response) |
0 commit comments