Beispiel #1
0
    def test_create_keypair_exception(self):
        KEYPAIR_NAME = 'newKeypair'

        formData = {'method': 'CreateKeypair',
                    'name': KEYPAIR_NAME,
                    }

        exception = engineclient_exceptions.ClientException('clientException',
                                                message='clientException')
        self.mox.StubOutWithMock(api, 'keypair_create')
        api.keypair_create(IsA(http.HttpRequest),
                           KEYPAIR_NAME).AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.post(
                   reverse('steer:engine:access_and_security:keypairs:create'),
                           formData)

        self.assertRedirectsNoFollow(res,
                 reverse('steer:engine:access_and_security:keypairs:create'))
Beispiel #2
0
    def test_create_keypair_exception(self):
        KEYPAIR_NAME = 'newKeypair'

        formData = {
            'method': 'CreateKeypair',
            'name': KEYPAIR_NAME,
        }

        exception = engineclient_exceptions.ClientException(
            'clientException', message='clientException')
        self.mox.StubOutWithMock(api, 'keypair_create')
        api.keypair_create(IsA(http.HttpRequest),
                           KEYPAIR_NAME).AndRaise(exception)

        self.mox.ReplayAll()

        res = self.client.post(
            reverse('steer:engine:access_and_security:keypairs:create'),
            formData)

        self.assertRedirectsNoFollow(
            res, reverse('steer:engine:access_and_security:keypairs:create'))
Beispiel #3
0
    def test_create_keypair_post(self):
        KEYPAIR_NAME = 'newKeypair'
        PRIVATE_KEY = 'privateKey'

        newKeyPair = self.mox.CreateMock(api.KeyPair)
        newKeyPair.name = KEYPAIR_NAME
        newKeyPair.private_key = PRIVATE_KEY

        formData = {'method': 'CreateKeypair',
                    'name': KEYPAIR_NAME,
                    }

        self.mox.StubOutWithMock(api, 'keypair_create')
        api.keypair_create(IsA(http.HttpRequest),
                           KEYPAIR_NAME).AndReturn(newKeyPair)

        self.mox.ReplayAll()

        res = self.client.post(
                   reverse('steer:engine:access_and_security:keypairs:create'),
                           formData)

        self.assertTrue(res.has_header('Content-Disposition'))
Beispiel #4
0
 def handle(self, request, data):
     try:
         LOG.info('Creating keypair "%s"' % data['name'])
         keypair = api.keypair_create(request, data['name'])
         response = http.HttpResponse(mimetype='application/binary')
         response['Content-Disposition'] = \
                  'attachment; filename=%s.pem' % slugify(keypair.name)
         response.write(keypair.private_key)
         response['Content-Length'] = str(len(response.content))
         return response
     except engineclient_exceptions.ClientException, e:
         LOG.exception("ClientException in CreateKeyPair")
         messages.error(request,
                        _('Error Creating Keypair: %s') % e.message)
         return shortcuts.redirect(request.build_absolute_uri())
Beispiel #5
0
    def test_create_keypair_post(self):
        KEYPAIR_NAME = 'newKeypair'
        PRIVATE_KEY = 'privateKey'

        newKeyPair = self.mox.CreateMock(api.KeyPair)
        newKeyPair.name = KEYPAIR_NAME
        newKeyPair.private_key = PRIVATE_KEY

        formData = {
            'method': 'CreateKeypair',
            'name': KEYPAIR_NAME,
        }

        self.mox.StubOutWithMock(api, 'keypair_create')
        api.keypair_create(IsA(http.HttpRequest),
                           KEYPAIR_NAME).AndReturn(newKeyPair)

        self.mox.ReplayAll()

        res = self.client.post(
            reverse('steer:engine:access_and_security:keypairs:create'),
            formData)

        self.assertTrue(res.has_header('Content-Disposition'))