Exemplo n.º 1
0
 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')
Exemplo n.º 2
0
 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', '')
Exemplo n.º 3
0
 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))
Exemplo n.º 4
0
 def test_ingest_tarball_not_configured(self):
     with self.assertRaises(auth.AuthorizationError):
         importer.ingest_tarball('zzz', '')
Exemplo n.º 5
0
    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())