Ejemplo n.º 1
0
def test_unexpired_invite_is_revokable():
    portfolio = PortfolioFactory.create()
    user = UserFactory.create()
    portfolio_role = PortfolioRoleFactory.create(
        portfolio=portfolio, user=user, status=PortfolioRoleStatus.PENDING)
    invite = PortfolioInvitationFactory.create(role=portfolio_role)
    assert invite.is_revokable
Ejemplo n.º 2
0
def test_invite_is_not_revokable_if_invite_is_not_pending():
    portfolio = PortfolioFactory.create()
    user = UserFactory.create()
    portfolio_role = PortfolioRoleFactory.create(
        portfolio=portfolio, user=user, status=PortfolioRoleStatus.PENDING)
    invite = PortfolioInvitationFactory.create(
        role=portfolio_role, status=InvitationStatus.ACCEPTED)
    assert not invite.is_revokable
Ejemplo n.º 3
0
def test_revoke_invitation():
    portfolio = PortfolioFactory.create()
    user = UserFactory.create()
    role = PortfolioRoleFactory.create(user=user, portfolio=portfolio)
    invite = PortfolioInvitationFactory.create(role=role, dod_id=user.dod_id)
    assert invite.is_pending
    PortfolioInvitations.revoke(invite.token)
    assert invite.is_revoked
    assert invite.role.status == PortfolioRoleStatus.DISABLED
Ejemplo n.º 4
0
def test_wrong_user_accepts_invitation():
    user = UserFactory.create()
    portfolio = PortfolioFactory.create()
    role = PortfolioRoleFactory.create(portfolio=portfolio)
    wrong_user = UserFactory.create()
    invite = PortfolioInvitationFactory.create(role=role, dod_id=user.dod_id)
    with pytest.raises(WrongUserError):
        PortfolioInvitations.accept(wrong_user, invite.token)
    assert invite.role.status == PortfolioRoleStatus.PENDING
Ejemplo n.º 5
0
def test_accept_invitation_twice():
    portfolio = PortfolioFactory.create()
    user = UserFactory.create()
    role = PortfolioRoleFactory.create(portfolio=portfolio)
    invite = PortfolioInvitationFactory.create(role=role, dod_id=user.dod_id)
    PortfolioInvitations.accept(user, invite.token)
    with pytest.raises(InvitationError):
        PortfolioInvitations.accept(user, invite.token)
    assert invite.role.is_active
Ejemplo n.º 6
0
def test_accept_revoked_invite():
    user = UserFactory.create()
    portfolio = PortfolioFactory.create()
    role = PortfolioRoleFactory.create(portfolio=portfolio)
    invite = PortfolioInvitationFactory.create(status=InvitationStatus.REVOKED,
                                               role=role,
                                               dod_id=user.dod_id)
    with pytest.raises(InvitationError):
        PortfolioInvitations.accept(user, invite.token)
    assert invite.role.status == PortfolioRoleStatus.PENDING
Ejemplo n.º 7
0
def test_audit_event_for_accepted_invite():
    portfolio = PortfolioFactory.create()
    user = UserFactory.create()
    role = PortfolioRoleFactory.create(portfolio=portfolio)
    invite = PortfolioInvitationFactory.create(role=role, dod_id=user.dod_id)
    invite = PortfolioInvitations.accept(user, invite.token)

    accepted_event = AuditLog.get_by_resource(invite.id)[0]
    assert "email" in accepted_event.event_details
    assert "dod_id" in accepted_event.event_details
Ejemplo n.º 8
0
def test_resend_invitation(session):
    portfolio = PortfolioFactory.create()
    user = UserFactory.create()
    role = PortfolioRoleFactory.create(portfolio=portfolio)
    first_invite = PortfolioInvitationFactory.create(role=role,
                                                     dod_id=user.dod_id)
    assert first_invite.is_pending
    second_invite = PortfolioInvitations.resend(user, first_invite.token)
    assert first_invite.is_revoked
    assert second_invite.is_pending
Ejemplo n.º 9
0
def test_expired_invite_is_not_revokable():
    portfolio = PortfolioFactory.create()
    user = UserFactory.create()
    portfolio_role = PortfolioRoleFactory.create(
        portfolio=portfolio, user=user, status=PortfolioRoleStatus.PENDING)
    invite = PortfolioInvitationFactory.create(
        expiration_time=datetime.datetime.now() -
        datetime.timedelta(minutes=60),
        role=portfolio_role,
    )
    assert not invite.is_revokable
Ejemplo n.º 10
0
def test_accept_expired_invitation():
    user = UserFactory.create()
    portfolio = PortfolioFactory.create()
    role = PortfolioRoleFactory.create(portfolio=portfolio)
    increment = PortfolioInvitations.EXPIRATION_LIMIT_MINUTES + 1
    expiration_time = datetime.datetime.now() - datetime.timedelta(
        minutes=increment)
    invite = PortfolioInvitationFactory.create(
        expiration_time=expiration_time,
        status=InvitationStatus.PENDING,
        role=role,
        dod_id=user.dod_id,
    )
    with pytest.raises(ExpiredError):
        PortfolioInvitations.accept(user, invite.token)

    assert invite.is_rejected
    assert invite.role.status == PortfolioRoleStatus.PENDING