def testNominal(self): self.mox.StubOutWithMock(models.LuksAccessLog, 'Log') metadata = { 'etc': 'anything', 'hdd_serial': 'anything', 'hostname': 'anything', 'owner': 'anything', 'platform_uuid': 'anything', } volume_uuid = 'foovolumeuuid' passphrase = 'passphrase' self.mox.StubOutWithMock(self.c, '_CreateNewSecretEntity') mock_entity = models.LuksVolume(key_name=volume_uuid, volume_uuid=volume_uuid, passphrase=passphrase) self.c._CreateNewSecretEntity('owner', volume_uuid, passphrase).AndReturn(mock_entity) self.mox.StubOutWithMock(mock_entity, 'put') mock_entity.put() models.LuksAccessLog.Log(entity=mock_entity, message='PUT', request=self.c.request) self.c.response = self.mox.CreateMockAnything() self.c.response.out = self.mox.CreateMockAnything() self.c.response.out.write(mox.IsA(basestring)) self.mox.ReplayAll() self.c.PutNewSecret('owner', volume_uuid, passphrase, metadata) self.mox.VerifyAll()
def testBarcodeTooLong(self): vol_uuid = str(uuid.uuid4()).upper() secret = str(uuid.uuid4()) * 10 models.User( key_name='*****@*****.**', user=users.get_current_user(), luks_perms=[permissions.RETRIEVE_OWN], ).put() models.LuksVolume( key_name=vol_uuid, owner='stub', hdd_serial='stub', hostname='stub', passphrase=secret, platform_uuid='stub', ).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=0' % vol_uuid) self.assertNotIn('<img class="qr_code" ', resp.body)
def testLuksAsOwner(self): vol_uuid = str(uuid.uuid4()).upper() secret = str(uuid.uuid4()) models.User( key_name='*****@*****.**', user=users.get_current_user(), luks_perms=[permissions.RETRIEVE_OWN], ).put() models.LuksVolume( key_name=vol_uuid, owner='stub', hdd_serial='stub', hostname='stub', passphrase=secret, platform_uuid='stub', ).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/' + vol_uuid) self.assertEqual(200, resp.status_int) self.assertIn('{"passphrase": "%s"}' % secret, resp.body)
def testLuksAsNonOwner(self): vol_uuid = str(uuid.uuid4()).upper() secret = str(uuid.uuid4()) models.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 testBarcode(self): vol_uuid = str(uuid.uuid4()).upper() secret = str(uuid.uuid4()) models.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.assertTrue(o['qr_img_url'])
def _CreateNewSecretEntity(self, owner, volume_uuid, secret): return models.LuksVolume(owner=owner, volume_uuid=volume_uuid, passphrase=str(secret))