|
|
@@ -15,3 +15,35 @@
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
# See the License for the specific language governing permissions and
|
|
|
# limitations under the License.
|
|
|
+
|
|
|
+from nose.tools import assert_true, assert_equal, assert_false
|
|
|
+
|
|
|
+from desktop.lib.django_test_util import make_logged_in_client
|
|
|
+from desktop.lib.test_utils import grant_access
|
|
|
+
|
|
|
+from django.contrib.auth.models import User, Group
|
|
|
+from django.core.urlresolvers import reverse
|
|
|
+
|
|
|
+from useradmin.models import HuePermission, GroupPermission
|
|
|
+
|
|
|
+
|
|
|
+class TestSecurity():
|
|
|
+
|
|
|
+ def test_permissions(self):
|
|
|
+ client = make_logged_in_client(username='test_permissions', groupname='test_permissions', is_superuser=False)
|
|
|
+ grant_access("test_permissions", "test_permissions", "security")
|
|
|
+ user = User.objects.get(username='test_permissions')
|
|
|
+
|
|
|
+ def check(client, assertz):
|
|
|
+ response = client.get(reverse("security:hive"))
|
|
|
+ assertz("Impersonate the user" in response.content, response.content)
|
|
|
+
|
|
|
+ # Forbidden
|
|
|
+ check(client, assert_false)
|
|
|
+
|
|
|
+ # Allowed
|
|
|
+ group, created = Group.objects.get_or_create(name='test_permissions')
|
|
|
+ perm, created = HuePermission.objects.get_or_create(app='security', action='impersonate')
|
|
|
+ GroupPermission.objects.get_or_create(group=group, hue_permission=perm)
|
|
|
+
|
|
|
+ check(client, assert_true)
|