コード例 #1
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
    def test_has_permission_on_parent_node_copyto_fail_if_not_registration(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, parent=self.node)

        assert_false(component.has_permission(self.user, 'write'))
        with assert_raises(HTTPError):
            views.check_access(component, Auth(user=self.user), 'copyto', None)
コード例 #2
0
    def test_has_permission_on_parent_node_copyto_fail_if_not_registration(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, parent=self.node)

        assert_false(component.has_permission(self.user, 'write'))
        with assert_raises(HTTPError):
            views.check_access(component, Auth(user=self.user), 'copyto', None)
コード例 #3
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
    def test_has_permission_read_scope_write_action_forbidden(self):
        component = ProjectFactory(creator=self.user, is_public=False, parent=self.node)
        cas_resp = cas.CasResponse(authenticated=True, status=None, user=self.user._id,
                                   attributes={'accessTokenScope': {'osf.nodes.data_read'}})

        assert_true(component.has_permission(self.user, 'write'))
        with assert_raises(HTTPError) as exc_info:
            views.check_access(component, Auth(user=self.user), 'upload', cas_resp)
        assert_equal(exc_info.exception.code, 403)
コード例 #4
0
    def test_has_permission_read_scope_write_action_forbidden(self):
        component = ProjectFactory(creator=self.user, is_public=False, parent=self.node)
        cas_resp = cas.CasResponse(authenticated=True, status=None, user=self.user._id,
                                   attributes={'accessTokenScope': {'osf.nodes.data_read'}})

        assert_true(component.has_permission(self.user, 'write'))
        with assert_raises(HTTPError) as exc_info:
            views.check_access(component, Auth(user=self.user), 'upload', cas_resp)
        assert_equal(exc_info.exception.code, 403)
コード例 #5
0
    def test_has_permission_private_not_authenticated(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, is_public=False, parent=self.node)
        cas_resp = cas.CasResponse(authenticated=False)

        assert_false(component.has_permission(self.user, 'write'))
        with assert_raises(HTTPError) as exc_info:
            views.check_access(component, Auth(user=self.user), 'download', cas_resp)
        assert_equal(exc_info.exception.code, 403)
コード例 #6
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
    def test_has_permission_private_not_authenticated(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, is_public=False, parent=self.node)
        cas_resp = cas.CasResponse(authenticated=False)

        assert_false(component.has_permission(self.user, 'write'))
        with assert_raises(HTTPError) as exc_info:
            views.check_access(component, Auth(user=self.user), 'download', cas_resp)
        assert_equal(exc_info.exception.code, 403)
コード例 #7
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
    def test_has_permission_private_irrelevant_scope_forbidden(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, is_public=False, parent=self.node)
        cas_resp = cas.CasResponse(authenticated=True, status=None, user=self.user._id,
                                   attributes={'accessTokenScope': {'osf.users.all_read'}})

        assert_false(component.has_permission(self.user, 'write'))
        with assert_raises(HTTPError) as exc_info:
            views.check_access(component, Auth(user=self.user), 'download', cas_resp)
        assert_equal(exc_info.exception.code, 403)
コード例 #8
0
    def test_has_permission_private_irrelevant_scope_forbidden(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, is_public=False, parent=self.node)
        cas_resp = cas.CasResponse(authenticated=True, status=None, user=self.user._id,
                                   attributes={'accessTokenScope': {'osf.users.all_read'}})

        assert_false(component.has_permission(self.user, 'write'))
        with assert_raises(HTTPError) as exc_info:
            views.check_access(component, Auth(user=self.user), 'download', cas_resp)
        assert_equal(exc_info.exception.code, 403)
コード例 #9
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
 def test_has_permission_download_on_component_prereg_challenge_admin(self):
     try:
         res = views.check_access(self.draft_registration.branched_from._nodes.first(),
                                  Auth(user=self.prereg_challenge_admin_user), 'download', None)
     except Exception:
         self.fail()
     assert_true(res)
コード例 #10
0
    def test_has_permission_on_parent_node_copyfrom(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, is_public=False, parent=self.node)

        assert_false(component.has_permission(self.user, 'write'))
        res = views.check_access(component, Auth(user=self.user), 'copyfrom', None)
        assert_true(res)
コード例 #11
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
    def test_has_permission_on_parent_node_copyfrom(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, is_public=False, parent=self.node)

        assert_false(component.has_permission(self.user, 'write'))
        res = views.check_access(component, Auth(user=self.user), 'copyfrom', None)
        assert_true(res)
コード例 #12
0
 def test_has_permission_download_on_component_prereg_challenge_admin(self):
     try:
         res = views.check_access(self.draft_registration.branched_from._nodes.first(),
                                  Auth(user=self.prereg_challenge_admin_user), 'download', None)
     except Exception:
         self.fail()
     assert_true(res)
コード例 #13
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
    def test_has_permission_on_parent_node_metadata_pass_if_registration(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, parent=self.node, is_public=False)

        component_registration = RegistrationFactory(project=component, creator=component_admin)

        assert_false(component_registration.has_permission(self.user, 'read'))
        res = views.check_access(component_registration, Auth(user=self.user), 'metadata', None)
        assert_true(res)
コード例 #14
0
    def test_has_permission_write_scope_read_action(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, is_public=False, parent=self.node)
        cas_resp = cas.CasResponse(authenticated=True, status=None, user=self.user._id,
                                   attributes={'accessTokenScope': {'osf.nodes.data_write'}})

        assert_false(component.has_permission(self.user, 'write'))
        res = views.check_access(component, Auth(user=self.user), 'download', cas_resp)
        assert_true(res)
コード例 #15
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
    def test_has_permission_write_scope_read_action(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, is_public=False, parent=self.node)
        cas_resp = cas.CasResponse(authenticated=True, status=None, user=self.user._id,
                                   attributes={'accessTokenScope': {'osf.nodes.data_write'}})

        assert_false(component.has_permission(self.user, 'write'))
        res = views.check_access(component, Auth(user=self.user), 'download', cas_resp)
        assert_true(res)
コード例 #16
0
    def test_has_permission_on_parent_node_metadata_pass_if_registration(self):
        component_admin = AuthUserFactory()
        component = ProjectFactory(creator=component_admin, parent=self.node, is_public=False)

        component_registration = RegistrationFactory(project=component, creator=component_admin)

        assert_false(component_registration.has_permission(self.user, 'read'))
        res = views.check_access(component_registration, Auth(user=self.user), 'metadata', None)
        assert_true(res)
コード例 #17
0
    def test_has_permission_on_parent_node_copyto_pass_if_registration(self):
        component_admin = AuthUserFactory()
        ProjectFactory(creator=component_admin, parent=self.node)
        registration = RegistrationFactory(project=self.node)

        component_registration = registration._nodes.first()

        assert_false(component_registration.has_permission(self.user, 'write'))
        res = views.check_access(component_registration, Auth(user=self.user), 'copyto', None)
        assert_true(res)
コード例 #18
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
    def test_has_permission_on_parent_node_copyto_pass_if_registration(self):
        component_admin = AuthUserFactory()
        ProjectFactory(creator=component_admin, parent=self.node)
        registration = RegistrationFactory(project=self.node)

        component_registration = registration._nodes.first()

        assert_false(component_registration.has_permission(self.user, 'write'))
        res = views.check_access(component_registration, Auth(user=self.user), 'copyto', None)
        assert_true(res)
コード例 #19
0
 def test_has_permission_download_not_prereg_challenge_admin(self):
     new_user = AuthUserFactory()
     with assert_raises(HTTPError) as exc_info:
         views.check_access(self.draft_registration.branched_from,
              Auth(user=new_user), 'download', None)
         assert_equal(exc_info.exception.code, http.FORBIDDEN)
コード例 #20
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
 def test_not_has_permission_logged_in(self):
     user2 = AuthUserFactory()
     with assert_raises(HTTPError) as exc_info:
         views.check_access(self.node, Auth(user=user2), 'download', None)
     assert_equal(exc_info.exception.code, 403)
コード例 #21
0
 def test_has_permission_download_prereg_challenge_admin(self):
     res = views.check_access(self.draft_registration.branched_from,
         Auth(user=self.prereg_challenge_admin_user), 'download', None)
     assert_true(res)
コード例 #22
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
 def test_has_permission_download_prereg_challenge_admin(self):
     res = views.check_access(self.draft_registration.branched_from,
         Auth(user=self.prereg_challenge_admin_user), 'download', None)
     assert_true(res)
コード例 #23
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
 def test_not_has_permission_read_has_link(self):
     link = new_private_link('red-special', self.user, [self.node], anonymous=False)
     views.check_access(self.node, Auth(private_key=link.key), 'download', None)
コード例 #24
0
 def test_not_has_permission_not_logged_in(self):
     with assert_raises(HTTPError) as exc_info:
         views.check_access(self.node, Auth(), 'download', None)
     assert_equal(exc_info.exception.code, 401)
コード例 #25
0
 def test_not_has_permission_logged_in(self):
     user2 = AuthUserFactory()
     with assert_raises(HTTPError) as exc_info:
         views.check_access(self.node, Auth(user=user2), 'download', None)
     assert_equal(exc_info.exception.code, 403)
コード例 #26
0
 def test_not_has_permission_read_has_link(self):
     link = new_private_link('red-special', self.user, [self.node], anonymous=False)
     views.check_access(self.node, Auth(private_key=link.key), 'download', None)
コード例 #27
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
 def test_has_permission_download_not_prereg_challenge_admin(self):
     new_user = AuthUserFactory()
     with assert_raises(HTTPError) as exc_info:
         views.check_access(self.draft_registration.branched_from,
              Auth(user=new_user), 'download', None)
         assert_equal(exc_info.exception.code, http.FORBIDDEN)
コード例 #28
0
 def test_has_permission_download_prereg_challenge_admin_not_draft(self):
     with assert_raises(HTTPError) as exc_info:
         views.check_access(self.node,
              Auth(user=self.prereg_challenge_admin_user), 'download', None)
         assert_equal(exc_info.exception.code, http.FORBIDDEN)
コード例 #29
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
 def test_has_permission_download_prereg_challenge_admin_not_draft(self):
     with assert_raises(HTTPError) as exc_info:
         views.check_access(self.node,
              Auth(user=self.prereg_challenge_admin_user), 'download', None)
         assert_equal(exc_info.exception.code, http.FORBIDDEN)
コード例 #30
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
 def test_has_permission_write_prereg_challenge_admin(self):
     with assert_raises(HTTPError) as exc_info:
         views.check_access(self.draft_registration.branched_from,
             Auth(user=self.prereg_challenge_admin_user), 'write', None)
         assert_equal(exc_info.exception.code, http.FORBIDDEN)
コード例 #31
0
 def test_has_permission_write_prereg_challenge_admin(self):
     with assert_raises(HTTPError) as exc_info:
         views.check_access(self.draft_registration.branched_from,
             Auth(user=self.prereg_challenge_admin_user), 'write', None)
         assert_equal(exc_info.exception.code, http.FORBIDDEN)
コード例 #32
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
 def test_not_has_permission_read_public(self):
     self.node.is_public = True
     self.node.save()
     views.check_access(self.node, Auth(), 'download', None)
コード例 #33
0
 def test_not_has_permission_read_public(self):
     self.node.is_public = True
     self.node.save()
     views.check_access(self.node, Auth(), 'download', None)
コード例 #34
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
 def test_not_has_permission_not_logged_in(self):
     with assert_raises(HTTPError) as exc_info:
         views.check_access(self.node, Auth(), 'download', None)
     assert_equal(exc_info.exception.code, 401)
コード例 #35
0
 def test_has_permission(self):
     res = views.check_access(self.node, Auth(user=self.user), 'upload', None)
     assert_true(res)
コード例 #36
0
ファイル: test_addons.py プロジェクト: leb2dg/osf.io
 def test_has_permission(self):
     res = views.check_access(self.node, Auth(user=self.user), 'upload', None)
     assert_true(res)