-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from smaht-dac/tests
Add More Tests
- Loading branch information
Showing
40 changed files
with
1,411 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "encoded" | ||
version = "0.0.4" | ||
version = "0.0.5" | ||
description = "SMaHT Data Analysis Portal" | ||
authors = ["4DN-DCIC Team <[email protected]>"] | ||
license = "MIT" | ||
|
@@ -42,7 +42,7 @@ certifi = ">=2021.5.30" | |
chardet = "3.0.4" | ||
codeguru-profiler-agent = "^1.2.4" | ||
colorama = "0.3.3" | ||
dcicsnovault = "8.2.0.1b42" | ||
dcicsnovault = "8.2.0.1b45" | ||
dcicutils = "7.5.1.1b0" | ||
encoded-core = "^0.0.2" | ||
elasticsearch = "7.13.4" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
import os | ||
|
||
|
||
APP_VERSION_REGISTRY_KEY = 'snovault.app_version' | ||
|
||
|
||
ENCODED_ROOT_DIR = os.path.dirname(__file__) | ||
PROJECT_DIR = os.path.dirname(os.path.dirname(ENCODED_ROOT_DIR)) # two levels of hierarchy up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import pytest | ||
import unittest | ||
|
||
from pyramid.interfaces import IAuthenticationPolicy | ||
from pyramid.security import Authenticated, Everyone | ||
from pyramid.testing import DummyRequest | ||
from zope.interface.verify import verifyClass, verifyObject | ||
from ..authentication import NamespacedAuthenticationPolicy | ||
|
||
|
||
pytestmark = [pytest.mark.setone, pytest.mark.working] | ||
|
||
|
||
class TestNamespacedAuthenticationPolicy(unittest.TestCase): | ||
""" This is a modified version of TestRemoteUserAuthenticationPolicy | ||
""" | ||
def _getTargetClass(self): | ||
return NamespacedAuthenticationPolicy | ||
|
||
def _makeOne(self, namespace='user', | ||
base='pyramid.authentication.RemoteUserAuthenticationPolicy', | ||
*args, **kw): | ||
return self._getTargetClass()(namespace, base, *args, **kw) | ||
|
||
def test_class_implements_IAuthenticationPolicy(self): | ||
klass = self._makeOne().__class__ | ||
verifyClass(IAuthenticationPolicy, klass) | ||
|
||
def test_instance_implements_IAuthenticationPolicy(self): | ||
verifyObject(IAuthenticationPolicy, self._makeOne()) | ||
|
||
def test_unauthenticated_userid_returns_None(self): | ||
request = DummyRequest(environ={}) | ||
policy = self._makeOne() | ||
self.assertEqual(policy.unauthenticated_userid(request), None) | ||
|
||
def test_unauthenticated_userid(self): | ||
request = DummyRequest(environ={'REMOTE_USER':'fred'}) | ||
policy = self._makeOne() | ||
self.assertEqual(policy.unauthenticated_userid(request), 'user.fred') | ||
|
||
def test_authenticated_userid_None(self): | ||
request = DummyRequest(environ={}) | ||
policy = self._makeOne() | ||
self.assertEqual(policy.authenticated_userid(request), None) | ||
|
||
def test_authenticated_userid(self): | ||
request = DummyRequest(environ={'REMOTE_USER':'fred'}) | ||
policy = self._makeOne() | ||
self.assertEqual(policy.authenticated_userid(request), 'user.fred') | ||
|
||
def test_effective_principals_None(self): | ||
request = DummyRequest(environ={}) | ||
policy = self._makeOne() | ||
self.assertEqual(policy.effective_principals(request), [Everyone]) | ||
|
||
def test_effective_principals(self): | ||
request = DummyRequest(environ={'REMOTE_USER':'fred'}) | ||
policy = self._makeOne() | ||
self.assertEqual(policy.effective_principals(request), | ||
[Everyone, Authenticated, 'user.fred']) | ||
|
||
def test_remember(self): | ||
request = DummyRequest(environ={'REMOTE_USER':'fred'}) | ||
policy = self._makeOne() | ||
result = policy.remember(request, 'fred') | ||
self.assertEqual(result, []) | ||
|
||
def test_forget(self): | ||
request = DummyRequest(environ={'REMOTE_USER':'fred'}) | ||
policy = self._makeOne() | ||
result = policy.forget(request) | ||
self.assertEqual(result, []) | ||
|
||
# From TestSessionAuthenticationPolicy | ||
|
||
def test_session_remember(self): | ||
request = DummyRequest() | ||
policy = self._makeOne( | ||
base='pyramid.authentication.SessionAuthenticationPolicy', | ||
prefix='') | ||
result = policy.remember(request, 'user.fred') | ||
self.assertEqual(request.session.get('userid'), 'fred') | ||
self.assertEqual(result, []) | ||
self.assertEqual(policy.unauthenticated_userid(request), 'user.fred') | ||
|
||
def test_session_forget(self): | ||
request = DummyRequest(session={'userid':'fred'}) | ||
policy = self._makeOne( | ||
base='pyramid.authentication.SessionAuthenticationPolicy', | ||
prefix='') | ||
result = policy.forget(request) | ||
self.assertEqual(request.session.get('userid'), None) | ||
self.assertEqual(result, []) | ||
|
||
def test_session_forget_no_identity(self): | ||
request = DummyRequest() | ||
policy = self._makeOne( | ||
base='pyramid.authentication.SessionAuthenticationPolicy', | ||
prefix='') | ||
result = policy.forget(request) | ||
self.assertEqual(request.session.get('userid'), None) | ||
self.assertEqual(result, []) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
|
||
|
||
from .test_search import MockedRequest | ||
from snovault.util import is_admin_request | ||
|
||
|
||
pytestmark = [pytest.mark.working] | ||
|
||
|
||
@pytest.mark.parametrize('mock_request, expected', [ | ||
[MockedRequest(), False], | ||
[MockedRequest(principals_allowed=[ | ||
'group.admin' | ||
]), True], | ||
[MockedRequest(principals_allowed=[ | ||
'group.read-only-admin' | ||
]), False], # read only admin is not admin technically | ||
[MockedRequest(principals_allowed=[ | ||
'group.something-else' | ||
]), False], | ||
[MockedRequest(principals_allowed=[ | ||
'lots', 'of', 'other', 'perms', 'but', 'not', 'group', 'dot', 'admin' | ||
]), False] | ||
]) | ||
def test_authorization_is_admin_request(mock_request, expected): | ||
""" Checks that the request tests correctly resolve. """ | ||
assert is_admin_request(mock_request) is expected |
Oops, something went wrong.