def test_insert_item_bad_item_key(self, session, mock_crypto):
        mock_crypto.validate_signature.return_value = True, ""
        with app.test_request_context():
            g.session = MagicMock()
            response = MagicMock()
            response.status_code = 400
            response.content = b'[{"location": "$.", "error": "too lazy"}]'
            session.return_value.post.return_value = response

            payload = {
                "item": {
                    "local-land-charge": "Law 342",
                    "squamous": "place 342",
                    "elongated": "342"
                },
                "item-signature": "STUFF",
                "item-hash": "totallyfakehash"
            }

            response = self.app.post(
                '/record',
                data=json.dumps(payload),
                headers={'Content-Type': 'application/json'})
            self.assertEqual(response.status_code, 400)
            data = json.loads(response.data.decode())
            self.assertEqual(1, len(data))
            self.assertEqual("Item is invalid", data[0]['error'])
 def test_insert_multiple_list_with_rubbish(self, session):
     with app.test_request_context():
         g.session = MagicMock()
         response = MagicMock()
         response.status_code = 200
         session.return_value.post.return_value = response  # 3rd item will get this far
         payload = [{
             "item": {
                 "obtusity": "342"
             },
             "item-signature": "STUFF",
             "item-hash": "totallyfakehash"
         }, {
             "item": {
                 "challenge": "344"
             },
             "item-signature": "STUFF",
             "item-hash": "totallyfakehash2"
         }, {
             "item": {
                 "statutory-provisions": ["Law 342"],
                 "geometry": {
                     "type": "Point",
                     "coordinates": [1, 1]
                 },
                 "local-land-charge": 343,
                 "registration-date": "2012-09-01",
                 "charge-type": "Smoke Control Order",
                 "originating-authority": "Dave's Charge Shop",
                 "further-information": []
             },
             "item-signature": "STUFF",
             "item-hash": "totallyfakehash3"
         }]
         response = self.app.post(
             '/records',
             data=json.dumps(payload),
             headers={'Content-Type': 'application/json'})
         self.assertEqual(400, response.status_code)
         data = json.loads(response.data.decode())
         self.assertEqual(2, len(data))
         self.assertEqual("Item 0 is invalid", data[0]['error'])
         self.assertEqual("Item 1 is invalid", data[1]['error'])
Beispiel #3
0
 def test_no_match(self):
     with app.test_request_context():
         g.trace_id = 'test'
         self.assertEqual(self.cypto.validate_signature(test_payload, test_sig.replace('0', '2'), test_hash),
                          (False, 'Signature and payload do not match.'))
Beispiel #4
0
 def test_match(self):
     with app.test_request_context():
         g.trace_id = 'test'
         self.assertEqual(self.cypto.validate_signature(test_payload, test_sig, test_hash),
                          (True, "Signature and payload match."))
Beispiel #5
0
 def test_no_hash_match(self):
     with app.test_request_context():
         g.trace_id = 'test'
         self.assertEqual(self.cypto.validate_signature(test_payload, test_sig, "sha-256:MADEUP"),
                          (False, "Supplied hash does not match calculated hash."))
Beispiel #6
0
 def test_invalid_sig(self):
     with app.test_request_context():
         g.trace_id = 'test'
         self.assertEqual(self.cypto.validate_signature(test_payload, "NOTASIG", test_hash),
                          (False, "Invalid signature string 'NOTASIG'."))
Beispiel #7
0
 def test_invalid_hash(self):
     with app.test_request_context():
         g.trace_id = 'test'
         self.assertEqual(self.cypto.validate_signature(test_payload, test_sig, "NOTAHASH"),
                          (False, "Invalid hash string 'NOTAHASH'."))