def test_ingest_tarball_bad_tarball(self): put_config(""" tarball_upload { name: "tarball.tar.gz" authorized_uploader: "*****@*****.**" systems: "ldap" } """) with self.assertRaises(importer.BundleImportError): importer.ingest_tarball('tarball.tar.gz', 'zzzzzzz')
def test_ingest_tarball_unauthorized(self): put_config(""" tarball_upload { name: "tarball.tar.gz" authorized_uploader: "*****@*****.**" systems: "ldap" } """) with self.assertRaises(auth.AuthorizationError): importer.ingest_tarball('tarball.tar.gz', '')
def put(self, name): try: groups, auth_db_rev = importer.ingest_tarball( name, self.request.body) self.send_response({ 'groups': groups, 'auth_db_rev': auth_db_rev, }) except importer.BundleImportError as e: self.abort_with_error(400, error=str(e))
def test_ingest_tarball_not_configured(self): with self.assertRaises(auth.AuthorizationError): importer.ingest_tarball('zzz', '')
def test_ingest_tarball_happy(self): self.mock_now(datetime.datetime(2010, 1, 2, 3, 4, 5, 6)) put_config(""" tarball_upload { name: "tarball.tar.gz" authorized_uploader: "*****@*****.**" domain: "zzz.example.com" systems: "ldap" groups: "ldap/ok1" groups: "ldap/ok2" } """) tarball = build_tar_gz({ 'ldap/ok1': 'a', 'ldap/ok2': 'b', 'ldap/ignored': '1', 'ignored/zzz': '2', }) groups, rev = importer.ingest_tarball('tarball.tar.gz', tarball) self.assertEqual(['ldap/ok1', 'ldap/ok2'], groups) self.assertEqual(1, rev) expected_groups = { 'ldap/ok1': { 'auth_db_prev_rev': None, 'auth_db_rev': 1, 'created_by': auth.Identity(kind='user', name='*****@*****.**'), 'created_ts': datetime.datetime(2010, 1, 2, 3, 4, 5, 6), 'description': u'', 'globs': [], 'members': [auth.Identity(kind='user', name='*****@*****.**')], 'modified_by': auth.Identity(kind='user', name='*****@*****.**'), 'modified_ts': datetime.datetime(2010, 1, 2, 3, 4, 5, 6), 'nested': [], 'owners': u'administrators', }, 'ldap/ok2': { 'auth_db_prev_rev': None, 'auth_db_rev': 1, 'created_by': auth.Identity(kind='user', name='*****@*****.**'), 'created_ts': datetime.datetime(2010, 1, 2, 3, 4, 5, 6), 'description': u'', 'globs': [], 'members': [auth.Identity(kind='user', name='*****@*****.**')], 'modified_by': auth.Identity(kind='user', name='*****@*****.**'), 'modified_ts': datetime.datetime(2010, 1, 2, 3, 4, 5, 6), 'nested': [], 'owners': u'administrators', }, } self.assertEqual(expected_groups, fetch_groups()) # Same tarball again => noop. groups, rev = importer.ingest_tarball('tarball.tar.gz', tarball) self.assertEqual([], groups) self.assertEqual(0, rev) # Empty tarball => removes the groups, they are no longer exported. tarball = build_tar_gz({}) groups, rev = importer.ingest_tarball('tarball.tar.gz', tarball) self.assertEqual(['ldap/ok1', 'ldap/ok2'], groups) self.assertEqual(2, rev) # All are deleted. self.assertEqual({}, fetch_groups())