示例#1
0
 def installation_error2(self):
     decryt = AESCipher(self.password)
     encryt = json.loads(
         installation(self.username, self.password, 'API_KEY').encrypt())
     secret = encryt['secret'] = 'destroyed'
     self.assertRaises(base64.binascii.Error, AESCipher.decrypt, decryt,
                       secret)
示例#2
0
 def installation(self):
     decryt = AESCipher(self.password)
     encryt = json.loads(
         installation(self.username, self.password, 'API_KEY').encrypt())
     d = AESCipher.decrypt(decryt, encryt['secret'])
     self.assertIs(len(d), 4)
     self.assertTrue(isinstance(d, dict))
示例#3
0
 def installation_error1(self):
     decryt = AESCipher('wrong password')
     encryt = json.loads(installation(
         self.user, self.password, 'API_KEY').encrypt())
     self.assertRaises(
         UnicodeDecodeError,
         AESCipher.decrypt,
         decryt, encryt['secret']
     )
示例#4
0
    def setUp(self):
        fake = Faker()
        Proxy.objects.create(proxy_uri='')
        username = fake.name()
        password = fake.password()
        User.objects.create_user(username, '', password)
        encryption_password = fake.password()
        data = installation(username, encryption_password,
                            fake.sha1()).encrypt()
        self.factory = RequestFactory()
        self.user = authenticate(username=username, password=password)
        self.user.is_verified = lambda: True

        self.post_data = {
            'json': data,
            'pass': encryption_password,
        }
示例#5
0
    def post(self, request):
        form = self.generate_form(request.POST)
        user = User.objects.get(username=request.user)

        if form.is_valid():
            form_data = form.cleaned_data

            generate_data = installation(user,
                                         form_data['encryption_password'],
                                         form_data['API']).encrypt()

            registration = callback(
                json.loads(generate_data),
                user,
                form_data['encryption_password'],
            ).register()

            if registration.status_code is 200:
                response = HttpResponse(
                    generate_data, content_type='application/force-download')
                response[
                    'Content-Disposition'] = 'attachment; filename=%s' % smart_str(
                        'BunqWebApp.json')  # noqa

                user.save()
            else:
                error = {
                    "Error": [{
                        "error_description_translated":
                        'something whent wrong while registering your API key wiht the bunq servers'  # noqa
                    }]
                }
                response = HttpResponse(json.dumps(error))
            return response

        else:
            return render(request, self.template, {'form': form})
示例#6
0
def generate(request):
    '''
    This is working smooth.
    View that handles the /generate page.

    Need to find a way to test views where OTP is required.
    Maybe with mock tests or monkeyPatch.
    '''
    if request.method == 'POST':
        formKey = GenerateKeyForm(request.POST)
        if formKey.is_valid():
            username = request.user.username
            API = formKey.cleaned_data['API']
            encryption_password = formKey.cleaned_data['encryption_password']
            data = installation(username, encryption_password, API)
            encryptedData = data.encrypt()
            response = HttpResponse(
                encryptedData, content_type='application/force-download')
            response['Content-Disposition'] = 'attachment; filename=%s' % smart_str('BunqWebApp.json')  # noqa
            return response

    else:
        formKey = GenerateKeyForm()
    return render(request, 'BunqAPI/index.html', {'form': formKey})