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)
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))
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'] )
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, }
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})
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})