def test_parsing_complete_url(self): url = ( "/debug/meta/trim/300x200:400x500/adaptive-full-fit-in/-300x-400/" "left/top/smart/filters:brightness(100)/some/image.jpg" ) expected = { "trim": "trim", "full": True, "halign": "left", "fit_in": True, "vertical_flip": True, "image": "some/image.jpg", "crop": {"top": 200, "right": 400, "bottom": 500, "left": 300}, "height": 400, "width": 300, "meta": True, "horizontal_flip": True, "filters": "brightness(100)", "valign": "top", "debug": True, "adaptive": True, "smart": True, } result = Url.parse_decrypted(url) expect(result).not_to_be_null() expect(result).to_be_like(expected) # do it again to use compiled regex result = Url.parse_decrypted(url) expect(result).not_to_be_null() expect(result).to_be_like(expected)
def test_parsing_complete_url(self): url = ( "/debug/meta/trim/300x200:400x500/adaptive-full-fit-in/-300x-400/" "left/top/smart/auth:requester(CVZzFCbz4Rcf2Lmu9mvtC1CmvPukHy5kS2LNtNaBFM2N):contract(Du2kswW2h1gNVnTWdfNdSxBrC2F9ofoaZsXA6ki1PhG6):document(profile):field(avatarURL):owner(8vagK6r9BnYct3k8WWYXNFadY1hG8TjikR3SfXceFnRQ):updatedAt(1602042152761)/filters:brightness(100)/some/image.jpg" ) expected = { "trim": "trim", "full": True, "halign": "left", "fit_in": True, "vertical_flip": True, "image": "some/image.jpg", "crop": { "top": 200, "right": 400, "bottom": 500, "left": 300 }, "height": 400, "width": 300, "meta": True, "horizontal_flip": True, "auth": "requester(CVZzFCbz4Rcf2Lmu9mvtC1CmvPukHy5kS2LNtNaBFM2N):contract(Du2kswW2h1gNVnTWdfNdSxBrC2F9ofoaZsXA6ki1PhG6):document(profile):field(avatarURL):owner(8vagK6r9BnYct3k8WWYXNFadY1hG8TjikR3SfXceFnRQ):updatedAt(1602042152761)", "filters": "brightness(100)", "valign": "top", "debug": True, "adaptive": True, "smart": True, } result = Url.parse_decrypted(url) expect(result).not_to_be_null() expect(result).to_be_like(expected) # do it again to use compiled regex result = Url.parse_decrypted(url) expect(result).not_to_be_null() expect(result).to_be_like(expected)
def test_parsing_complete_url(self): url = ( "/debug/meta/trim/300x200:400x500/adaptive-full-fit-in/-300x-400/" "left/top/smart/filters:brightness(100)/some/image.jpg") expected = { "trim": "trim", "full": True, "halign": "left", "fit_in": True, "vertical_flip": True, "image": "some/image.jpg", "crop": { "top": 200, "right": 400, "bottom": 500, "left": 300 }, "height": 400, "width": 300, "meta": True, "horizontal_flip": True, "filters": "brightness(100)", "valign": "top", "debug": True, "adaptive": True, "smart": True, } result = Url.parse_decrypted(url) expect(result).not_to_be_null() expect(result).to_be_like(expected) # do it again to use compiled regex result = Url.parse_decrypted(url) expect(result).not_to_be_null() expect(result).to_be_like(expected)
def decrypt(self, encrypted): cipher = AES.new(self.security_key) try: debased = base64.urlsafe_b64decode(encrypted.encode("utf-8")) decrypted = cipher.decrypt(debased).rstrip('{') except TypeError: return None result = Url.parse_decrypted('/%s' % decrypted) result['image_hash'] = result['image'] del result['image'] return result
def test_parsing_complete_url(self): url = '/debug/meta/trim/300x200:400x500/adaptive-full-fit-in/-300x-400/' \ 'left/top/smart/filters:brightness(100)/some/image.jpg' expected = { 'trim': 'trim', 'full': True, 'halign': 'left', 'fit_in': True, 'vertical_flip': True, 'image': 'some/image.jpg', 'crop': { 'top': 200, 'right': 400, 'bottom': 500, 'left': 300 }, 'height': 400, 'width': 300, 'meta': True, 'horizontal_flip': True, 'filters': 'brightness(100)', 'valign': 'top', 'debug': True, 'adaptive': True, 'smart': True, } result = Url.parse_decrypted(url) expect(result).not_to_be_null() expect(result).to_be_like(expected) # do it again to use compiled regex result = Url.parse_decrypted(url) expect(result).not_to_be_null() expect(result).to_be_like(expected)
def test_parsing_invalid_url(self): expect(Url.compiled_regex).to_be_null() url = "" expect(Url.parse_decrypted(url)).to_be_null()