예제 #1
0
def test_get_named_config(test_type, environment, expected):
    """Assert that the named configurations can be loaded.

    Or that a KeyError is returned for missing config types.
    """
    if test_type == 'valid':
        assert isinstance(config.get_named_config(environment), expected)
    else:
        with pytest.raises(KeyError):
            config.get_named_config(environment)
예제 #2
0
 def status(self):
     """Calculate the status based on the config value."""
     current_time = datetime.now()
     if self.invitation_status_code == 'PENDING':
         expiry_time = self.sent_date + timedelta(days=int(get_named_config().TOKEN_EXPIRY_PERIOD))
         if current_time >= expiry_time:
             return 'EXPIRED'
     return self.invitation_status_code
예제 #3
0
def test_invitations_status_expiry(session):  # pylint:disable=unused-argument
    """Assert can set the status from PENDING to EXPIRED."""
    sent_date = datetime.now() - timedelta(
        days=int(get_named_config().TOKEN_EXPIRY_PERIOD) + 1)
    invitation = factory_invitation_model(session=session,
                                          status='PENDING',
                                          sent_date=sent_date)
    session.add(invitation)
    session.commit()

    result: str = invitation.status

    assert result == 'EXPIRED'
예제 #4
0
from auth_api.models import MembershipStatusCode as MembershipStatusCodeModel
from auth_api.models import MembershipType as MembershipTypeModel
from auth_api.models import Org as OrgModel
from auth_api.schemas import MembershipSchema
from auth_api.utils.enums import NotificationType, Status, LoginSource
from auth_api.utils.roles import ADMIN, ALL_ALLOWED_ROLES, COORDINATOR, STAFF
from auth_api.config import get_named_config

from .authorization import check_auth
from .keycloak import KeycloakService
from .notification import send_email
from .org import Org as OrgService
from .user import User as UserService

ENV = Environment(loader=FileSystemLoader('.'), autoescape=True)
CONFIG = get_named_config()


@ServiceTracing.trace(ServiceTracing.enable_tracing,
                      ServiceTracing.should_be_tracing)
class Membership:  # pylint: disable=too-many-instance-attributes,too-few-public-methods
    """Manages all aspects of the Membership Entity.

    This manages storing the Membership in the cache,
    ensuring that the local cache is up to date,
    submitting changes back to all storage systems as needed.
    """
    def __init__(self, model):
        """Return a membership service object."""
        self._model = model
예제 #5
0
Test Utility for creating test scenarios.
"""
import uuid
from enum import Enum
from faker import Faker
from random import choice
from string import ascii_lowercase, ascii_uppercase

from auth_api.services.keycloak_user import KeycloakUser
from auth_api.utils.enums import AccessType, IdpHint, LoginSource, ProductCode, OrgType, PaymentMethod
from auth_api.config import get_named_config

fake = Faker()

CONFIG = get_named_config('testing')

JWT_HEADER = {
    'alg': CONFIG.JWT_OIDC_TEST_ALGORITHMS,
    'typ': 'JWT',
    'kid': CONFIG.JWT_OIDC_TEST_AUDIENCE
}


class TestJwtClaims(dict, Enum):
    """Test scenarios of jwt claims."""

    no_role = {
        'iss': CONFIG.JWT_OIDC_TEST_ISSUER,
        'sub': 'f7a4a1d3-73a8-4cbc-a40f-bb1145302065',
        'firstname': fake.first_name(),
예제 #6
0
 def expires_on(self):
     """Calculate the expiry date based on the config value."""
     if self.invitation_status_code == 'PENDING':
         return self.sent_date + timedelta(days=int(get_named_config().TOKEN_EXPIRY_PERIOD))
     return None