示例#1
0
def test_teamsync_end_to_end(user_creation, invite_only_user_creation, auth_system_builder, config,
                             blacklisted_emails, app):
  with auth_system_builder() as auth:
    # Create an new team to sync.
    org = model.organization.get_organization('buynlarge')
    new_synced_team = model.team.create_team('synced2', org, 'member', 'Some synced team.')
    sync_team_info = model.team.set_team_syncing(new_synced_team, auth.federated_service, config)

    # Sync the team.
    assert sync_team(auth, sync_team_info)

    # Ensure we now have members.
    msg = 'Auth system: %s' % auth.federated_service
    sync_team_info = model.team.get_team_sync_information('buynlarge', 'synced2')
    team_members = list(model.team.list_team_users(sync_team_info.team))
    assert len(team_members) > 1, msg

    it, _ = auth.iterate_group_members(config)
    assert len(team_members) == len(list(it)), msg

    sync_team_info.last_updated = datetime.now() - timedelta(hours=6)
    sync_team_info.save()

    # Remove one of the members and force a sync again to ensure we re-link the correct users.
    first_member = team_members[0]
    model.team.remove_user_from_team('buynlarge', 'synced2', first_member.username, 'devtable')

    team_members2 = list(model.team.list_team_users(sync_team_info.team))
    assert len(team_members2) == 1, msg
    assert sync_team(auth, sync_team_info)

    team_members3 = list(model.team.list_team_users(sync_team_info.team))
    assert len(team_members3) > 1, msg
    assert set([m.id for m in team_members]) == set([m.id for m in team_members3])
示例#2
0
def test_syncing(user_creation, invite_only_user_creation, starting_membership, group_membership,
                 expected_membership, blacklisted_emails, app):
  org = model.organization.get_organization('buynlarge')

  # Necessary for the fake auth entries to be created in FederatedLogin.
  database.LoginService.create(name=_FAKE_AUTH)

  # Assert the team is empty, so we have a clean slate.
  sync_team_info = model.team.get_team_sync_information('buynlarge', 'synced')
  assert len(list(model.team.list_team_users(sync_team_info.team))) == 0

  # Add the existing starting members to the team.
  for starting_member in starting_membership:
    (quay_username, fakeauth_username) = starting_member
    if '+' in quay_username:
      # Add a robot.
      (_, shortname) = parse_robot_username(quay_username)
      robot, _ = model.user.create_robot(shortname, org)
      model.team.add_user_to_team(robot, sync_team_info.team)
    else:
      email = quay_username + '@devtable.com'

      if fakeauth_username is None:
        quay_user = model.user.create_user_noverify(quay_username, email)
      else:
        quay_user = model.user.create_federated_user(quay_username, email, _FAKE_AUTH,
                                                      fakeauth_username, False)

      model.team.add_user_to_team(quay_user, sync_team_info.team)

  # Call syncing on the team.
  fake_auth = FakeUsers(group_membership)
  assert sync_team(fake_auth, sync_team_info)

  # Ensure the last updated time and transaction_id's have changed.
  updated_sync_info = model.team.get_team_sync_information('buynlarge', 'synced')
  assert updated_sync_info.last_updated is not None
  assert updated_sync_info.transaction_id != sync_team_info.transaction_id

  users_expected = set([name for name in expected_membership if '+' not in name])
  robots_expected = set([name for name in expected_membership if '+' in name])
  assert len(users_expected) + len(robots_expected) == len(expected_membership)

  # Check that the team's users match those expected.
  service_user_map = model.team.get_federated_team_member_mapping(sync_team_info.team,
                                                                  _FAKE_AUTH)
  assert set(service_user_map.keys()) == users_expected

  quay_users = model.team.list_team_users(sync_team_info.team)
  assert len(quay_users) == len(users_expected)

  for quay_user in quay_users:
    fakeauth_record = model.user.lookup_federated_login(quay_user, _FAKE_AUTH)
    assert fakeauth_record is not None
    assert fakeauth_record.service_ident in users_expected
    assert service_user_map[fakeauth_record.service_ident] == quay_user.id

  # Check that the team's robots match those expected.
  robots_found = set([r.username for r in model.team.list_team_robots(sync_team_info.team)])
  assert robots_expected == robots_found
示例#3
0
def test_teamsync_existing_email(user_creation, invite_only_user_creation, auth_system_builder,
                                 blacklisted_emails, config, app):
  with auth_system_builder() as auth:
    # Create an new team to sync.
    org = model.organization.get_organization('buynlarge')
    new_synced_team = model.team.create_team('synced2', org, 'member', 'Some synced team.')
    sync_team_info = model.team.set_team_syncing(new_synced_team, auth.federated_service, config)

    # Add a new *unlinked* user with the same email address as one of the team members.
    it, _ = auth.iterate_group_members(config)
    members = list(it)
    model.user.create_user_noverify('someusername', members[0][0].email)

    # Sync the team and ensure it doesn't fail.
    assert sync_team(auth, sync_team_info)

    team_members = list(model.team.list_team_users(sync_team_info.team))
    assert len(team_members) > 0