Beispiel #1
0
def test_mark_namespace_for_deletion(initialized_db):
    def create_transaction(db):
        return db.transaction()

    # Create a user and then mark it for deletion.
    user = create_user_noverify("foobar",
                                "*****@*****.**",
                                email_required=False)

    # Add some robots.
    create_robot("foo", user)
    create_robot("bar", user)

    assert lookup_robot("foobar+foo") is not None
    assert lookup_robot("foobar+bar") is not None
    assert len(list(list_namespace_robots("foobar"))) == 2

    # Add some federated user links.
    attach_federated_login(user, "google", "someusername")
    attach_federated_login(user, "github", "someusername")
    assert FederatedLogin.select().where(
        FederatedLogin.user == user).count() == 2
    assert FederatedLogin.select().where(
        FederatedLogin.service_ident == "someusername").exists()

    # Mark the user for deletion.
    queue = WorkQueue("testgcnamespace", create_transaction)
    mark_namespace_for_deletion(user, [], queue)

    # Ensure the older user is still in the DB.
    older_user = User.get(id=user.id)
    assert older_user.username != "foobar"

    # Ensure the robots are deleted.
    with pytest.raises(InvalidRobotException):
        assert lookup_robot("foobar+foo")

    with pytest.raises(InvalidRobotException):
        assert lookup_robot("foobar+bar")

    assert len(list(list_namespace_robots(older_user.username))) == 0

    # Ensure the federated logins are gone.
    assert FederatedLogin.select().where(
        FederatedLogin.user == user).count() == 0
    assert (not FederatedLogin.select().where(
        FederatedLogin.service_ident == "someusername").exists())

    # Ensure we can create a user with the same namespace again.
    new_user = create_user_noverify("foobar",
                                    "*****@*****.**",
                                    email_required=False)
    assert new_user.id != user.id

    # Ensure the older user is still in the DB.
    assert User.get(id=user.id).username != "foobar"
Beispiel #2
0
def test_mark_namespace_for_deletion(initialized_db):
    def create_transaction(db):
        return db.transaction()

    # Create a user and then mark it for deletion.
    user = create_user_noverify("foobar",
                                "*****@*****.**",
                                email_required=False)

    # Add some robots.
    create_robot("foo", user)
    create_robot("bar", user)

    assert lookup_robot("foobar+foo") is not None
    assert lookup_robot("foobar+bar") is not None
    assert len(list(list_namespace_robots("foobar"))) == 2

    # Mark the user for deletion.
    queue = WorkQueue("testgcnamespace", create_transaction)
    mark_namespace_for_deletion(user, [], queue)

    # Ensure the older user is still in the DB.
    older_user = User.get(id=user.id)
    assert older_user.username != "foobar"

    # Ensure the robots are deleted.
    with pytest.raises(InvalidRobotException):
        assert lookup_robot("foobar+foo")

    with pytest.raises(InvalidRobotException):
        assert lookup_robot("foobar+bar")

    assert len(list(list_namespace_robots(older_user.username))) == 0

    # Ensure we can create a user with the same namespace again.
    new_user = create_user_noverify("foobar",
                                    "*****@*****.**",
                                    email_required=False)
    assert new_user.id != user.id

    # Ensure the older user is still in the DB.
    assert User.get(id=user.id).username != "foobar"
Beispiel #3
0
def test_delete_robot(initialized_db):
  # Create a robot account.
  user = create_user_noverify('foobar', '*****@*****.**', email_required=False)
  robot, _ = create_robot('foo', user)

  # Add some notifications and other rows pointing to the robot.
  create_notification('repo_push', robot)

  team = create_team('someteam', get_organization('buynlarge'), 'member')
  add_user_to_team(robot, team)

  # Ensure the robot exists.
  assert lookup_robot(robot.username).id == robot.id

  # Delete the robot.
  delete_robot(robot.username)

  # Ensure it is gone.
  with pytest.raises(InvalidRobotException):
    lookup_robot(robot.username)
Beispiel #4
0
def test_robot(initialized_db):
  # Create a robot account.
  user = create_user_noverify('foobar', '*****@*****.**', email_required=False)
  robot, token = create_robot('foo', user)
  assert retrieve_robot_token(robot) == token

  # Ensure we can retrieve its information.
  found = lookup_robot('foobar+foo')
  assert found == robot

  creds = get_pull_credentials('foobar+foo')
  assert creds is not None
  assert creds['username'] == 'foobar+foo'
  assert creds['password'] == token

  assert verify_robot('foobar+foo', token) == robot

  with pytest.raises(InvalidRobotException):
    assert verify_robot('foobar+foo', 'someothertoken')

  with pytest.raises(InvalidRobotException):
    assert verify_robot('foobar+unknownbot', token)
Beispiel #5
0
def test_robot(initialized_db):
    # Create a robot account.
    user = create_user_noverify("foobar",
                                "*****@*****.**",
                                email_required=False)
    robot, token = create_robot("foo", user)
    assert retrieve_robot_token(robot) == token

    # Ensure we can retrieve its information.
    found = lookup_robot("foobar+foo")
    assert found == robot

    creds = get_pull_credentials("foobar+foo")
    assert creds is not None
    assert creds["username"] == "foobar+foo"
    assert creds["password"] == token

    assert verify_robot("foobar+foo", token) == robot

    with pytest.raises(InvalidRobotException):
        assert verify_robot("foobar+foo", "someothertoken")

    with pytest.raises(InvalidRobotException):
        assert verify_robot("foobar+unknownbot", token)