def test_can_crud_passphrase(self): # Creating passphrase. passphrase = Passphrase(word='very_secret') passphrase.save() self.assertIsNotNone(passphrase.id) # Reading passphrase. all_passphrase = Passphrase.objects.all() self.assertIn(passphrase, all_passphrase) # Updating passphrase. passphrase.word = 'changed_from_very_secret' passphrase.save() # Deleting passphrase. passphrase.delete() with self.assertRaises(Passphrase.DoesNotExist): Passphrase.objects.get(word='changed_from_very_secret')
def decorated_func(viewset, request, pk=None, *args, **kwargs): passphrase = request.POST.get('passphrase', None) exists = Passphrase.exists(passphrase) if exists.status: request.passphrase = exists.matched_list[0] if pk: return func(viewset, request, pk, *args, **kwargs) return func(viewset, request, *args, **kwargs) else: content = {'status': 'Invalid passphrase'} status = status_code.HTTP_401_UNAUTHORIZED return Response(content, status=status)
def decorated_func(viewset, request, pk=None, *args, **kwargs): passphrase = request.POST.get("passphrase", None) if not passphrase: passphrase = request.data.get("passphrase", None) exists = Passphrase.exists(passphrase) if exists.status: request.passphrase = exists.matched_list[0] if pk: return func(viewset, request, pk, *args, **kwargs) return func(viewset, request, *args, **kwargs) else: content = { "status": "Invalid passphrase. Contact the admin to provide authorization" } status = status_code.HTTP_401_UNAUTHORIZED return Response(content, status=status)
def auth(self, request): passphrase = request.POST.get("passphrase", "") if not passphrase: content = { "status": "failed", "message": "Passphrase not supplied" } return Response(content, status=status_code.HTTP_400_BAD_REQUEST) exists = Passphrase.exists(passphrase) if not exists.status: content = { "status": "failed", "message": "Invalid Passphrase. Reach out to Ops!", } return Response(content, status=status_code.HTTP_401_UNAUTHORIZED) content = { "status": "success", "message": "Successfully authenticated." } return Response(content, status=status_code.HTTP_200_OK)