def setUp(self): super(LogsModuleTest, self).setUp() self.volume = volumes.LuksVolume(owner='stub', hdd_serial='stub', hostname='stub', passphrase='secret', platform_uuid='stub', volume_uuid='vol_uuid') self.testapp = webtest.TestApp(gae_main.app)
def testSilentRetrieve(self): vol_uuid = str(uuid.uuid4()).upper() secret = str(uuid.uuid4()) base.User( key_name='*****@*****.**', user=users.get_current_user(), luks_perms=[permissions.SILENT_RETRIEVE, permissions.RETRIEVE], ).put() models.LuksVolume( owner='stub', hdd_serial='stub', hostname='stub', passphrase=secret, platform_uuid='stub', volume_uuid=vol_uuid ).put() with mock.patch.object(util, 'SendEmail') as mock_send_email: resp = gae_main.app.get_response('/luks/%s?json=1' % vol_uuid) mock_send_email.assert_not_called() self.assertEqual(httplib.OK, resp.status_int)
def testLuksAsOwner(self): vol_uuid = str(uuid.uuid4()).upper() secret = str(uuid.uuid4()) base.User( key_name='*****@*****.**', user=users.get_current_user(), luks_perms=[permissions.RETRIEVE_OWN], ).put() models.LuksVolume( owner='stub7', hdd_serial='stub', hostname='stub', passphrase=secret, platform_uuid='stub', volume_uuid=vol_uuid ).put() with mock.patch.object(util, 'SendEmail') as _: resp = gae_main.app.get_response('/luks/%s?json=1' % vol_uuid) self.assertEqual(httplib.OK, resp.status_int) self.assertIn('"passphrase": "%s"' % secret, resp.body)
def testBarcode(self): vol_uuid = str(uuid.uuid4()).upper() secret = str(uuid.uuid4()) base.User( key_name='*****@*****.**', user=users.get_current_user(), luks_perms=[permissions.RETRIEVE_OWN], ).put() models.LuksVolume( owner='stub7', hdd_serial='stub', hostname='stub', passphrase=secret, platform_uuid='stub', volume_uuid=vol_uuid ).put() with mock.patch.object(util, 'SendEmail') as _: resp = gae_main.app.get_response('/luks/%s?json=1' % vol_uuid) o = util.FromSafeJson(resp.body) self.assertTrue(o['qr_img_url'])
def setUp(self): super(RekeyModuleTest, self).setUp() self.target_id = str(uuid.uuid4()).upper() self.v = models.LuksVolume( owner='*****@*****.**', volume_uuid=self.target_id, serial='stub', passphrase='SECRET', hdd_serial='stub', hostname='stub', platform_uuid='stub', active=True, ) self.testapp = webtest.TestApp(gae_main.app)
def testLuksAsNonOwner(self): vol_uuid = str(uuid.uuid4()).upper() secret = str(uuid.uuid4()) base.User( key_name='*****@*****.**', user=users.get_current_user(), luks_perms=[permissions.RETRIEVE_OWN], ).put() models.LuksVolume( owner='stub5', hdd_serial='stub', hostname='stub', passphrase=secret, platform_uuid='stub', volume_uuid=vol_uuid ).put() with mock.patch.object(handlers, 'settings') as mock_settings: mock_settings.XSRF_PROTECTION_ENABLED = False with mock.patch.object(util, 'SendEmail') as _: resp = gae_main.app.get_response('/luks/%s?json=1' % vol_uuid) self.assertEqual(httplib.FORBIDDEN, resp.status_int) self.assertIn('Access denied.', resp.body)
def testLuksAsNonOwner(self): vol_uuid = str(uuid.uuid4()).upper() secret = str(uuid.uuid4()) base.User( key_name='*****@*****.**', user=users.get_current_user(), luks_perms=[permissions.RETRIEVE_OWN], ).put() models.LuksVolume(owners=['stub5'], hdd_serial='stub', hostname='stub', passphrase=secret, platform_uuid='stub', volume_uuid=vol_uuid).put() with mock.patch.object(util, 'SendEmail') as _: resp = self.testapp.get('/luks/%s?json=1' % vol_uuid, status=httplib.FORBIDDEN) self.assertIn('Access denied.', resp.body)
def testBarcodeTooLong(self): vol_uuid = str(uuid.uuid4()).upper() secret = str(uuid.uuid4()) * 10 base.User( key_name='*****@*****.**', user=users.get_current_user(), luks_perms=[permissions.RETRIEVE_OWN], ).put() models.LuksVolume( owner='stub', hdd_serial='stub', hostname='stub', passphrase=secret, platform_uuid='stub', volume_uuid=vol_uuid ).put() with mock.patch.object(handlers, 'settings') as mock_settings: mock_settings.XSRF_PROTECTION_ENABLED = False with mock.patch.object(util, 'SendEmail') as _: resp = gae_main.app.get_response('/luks/%s?json=1' % vol_uuid) o = util.FromSafeJson(resp.body) self.assertFalse(o['qr_img_url'])
def _CreateNewSecretEntity(self, owner, volume_uuid, secret): return volumes.LuksVolume( owner=owner, volume_uuid=volume_uuid, passphrase=str(secret))