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 send_data(event, result, start_time): time_now = datetime.datetime.utcnow().isoformat() time_stamp = str(time_now) postDict = {} size = '-' filters = Url.parse_decrypted(event['path']) del filters['image'] if int(result['statusCode']) == 200: size = (len(result['body'] * 3)) / 4 postDict['Data'] = { 'Version': get_distribution('image_handler').version, 'Company': 'AWS', 'Name': 'AWS Serverless Image Handler', 'Region': os.environ.get('AWS_DEFAULT_REGION'), 'Filters': filters, 'StatusCode': result['statusCode'], 'ResponseSize': size, 'ResponseTime': round(timeit.default_timer() - start_time, 3) } postDict['TimeStamp'] = time_stamp postDict['Solution'] = 'SO0023' postDict['UUID'] = os.environ.get('UUID') # API Gateway URL to make HTTP POST call url = 'https://metrics.awssolutionsbuilder.com/generic' data = json.dumps(postDict) headers = {'content-type': 'application/json'} req = Request(url, data, headers) rsp = urlopen(req) content = rsp.read() rspcode = rsp.getcode() logging.debug('Response Code: {}'.format(rspcode)) logging.debug('Response Content: {}'.format(content)) return req
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 decrypt(self, encrypted): cipher = AES.new(self.security_key, MODE_ECB) 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 get(self, **kw): hash = kw['hash'] url = kw['image'] unsafe = kw['unsafe'] try: decrypted = decode_uri(url, self.cipher, is_decrypted=True) except Exception as e: logger = logging.getLogger(__name__) logger.error(u"GetError: %s" % str(e)) return self.check_image(kw) kwargs = Url.parse_decrypted(decrypted) kwargs['hash'] = hash kwargs['unsafe'] = unsafe crop = kwargs.pop("crop", {}) kwargs.update({"crop_{0}".format(key): crop[key] for key in ["bottom", "left", "right", "top"] if crop.has_key(key)}) self.check_image(kwargs)
def topic(self): return Url.parse_decrypted("some fake url")
def test_parsing_invalid_url(self): expect(Url.compiled_regex).to_be_null() url = "" expect(Url.parse_decrypted(url)).to_be_null()
def topic(self): return Url.parse_decrypted( '/90x100/my.image.path/unsafe/filters:watermark(s.glbimg.com/some/image.jpg,0,0,0)' '/some.domain/img/path/img.jpg')
def topic(self): return Url.parse_decrypted( '/filters:watermark(s.glbimg.com/es/ge/f/original/2011/03/29/orlandosilva_60.jpg,0,0,0):brightness(-50):grayscale()/img' )
def topic(self): return Url.parse_decrypted('/meta/10x11:12x13/fit-in/-300x-200/left/top/smart/filters:some_filter()/img')
def topic(self): return Url.parse_decrypted( '/meta/10x11:12x13/fit-in/-300x-200/left/top/smart/filters:some_filter()/img' )
def topic(self): image_url = 's.glbimg.com/es/ge/f/original/2011/03/29/orlandosilva_60.jpg' return Url.parse_decrypted( '/meta/10x11:12x13/-300x-200/left/top/smart/%s' % image_url)
def topic(self): image_url = 's.glbimg.com/es/ge/f/original/2011/03/29/orlandosilva_60.jpg' return Url.parse_decrypted('/meta/10x11:12x13/-300x-200/left/top/smart/%s' % image_url)
def topic(self): return Url.parse_decrypted( '/90x100/filters:brightness(-50):contrast(20)/my.image.path/unsafe/filters:watermark(s.glbimg.com/some/image.jpg,0,0,0)/some.domain/img/path/img.jpg' )
def topic(self): return Url.parse_decrypted( '/filters:watermark(s.glbimg.com/es/ge/f/original/2011/03/29/orlandosilva_60.jpg,0,0,0):brightness(-50):grayscale()/img')
def topic(self): return Url.parse_decrypted( '/90x100/filters:brightness(-50):contrast(20)/my.image.path/unsafe/filters:watermark(s.glbimg.com/some/image.jpg,0,0,0)/some.domain/img/path/img.jpg')
def topic(self): return Url.parse_decrypted( "/filters:watermark(s.glbimg.com/es/ge/f/original/2011/03/29/orlandosilva_60.jpg,0,0,0)/img" )