Skip to content

Commit

Permalink
Merge pull request #57 from SandhraSokhal/PLFM-8206.1
Browse files Browse the repository at this point in the history
PLFM-8206
  • Loading branch information
john-hill authored Jan 6, 2024
2 parents 2e11064 + 6987079 commit f350c40
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/scripts/glue_jobs/process_access_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import re
import sys
import urllib.parse

from awsglue.transforms import *
Expand Down Expand Up @@ -40,8 +41,7 @@ def __init__(self, mapping_list, partition_key):
super().__init__(mapping_list, partition_key)

def execute(self, dynamic_frame):
transformed_frame = dynamic_frame.map(f=ProcessAccessRecords.transform)
return transformed_frame.resolveChoice(specs=[("entity_id", "cast:long")])
return dynamic_frame.map(f=ProcessAccessRecords.transform)

# Process the access record
@staticmethod
Expand Down Expand Up @@ -189,6 +189,9 @@ def get_entity_id(requesturl):
entity_id = matcher.group(1)
if entity_id.startswith("syn"):
entity_id = entity_id[3:]
entity_id = int(entity_id)
if entity_id > sys.maxsize:
return None
return entity_id


Expand Down
39 changes: 24 additions & 15 deletions tests/test_process_access_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def test_get_client_for_none(self):
def test_get_client_version_for_web(self):
expected_output = "435.0"
real_output = ProcessAccessRecords.get_client_version("WEB",
"Synapse-Java-Client/431.0 Synapse-Web-Client/435.0")
"Synapse-Java-Client/431.0 Synapse-Web-Client/435.0")
self.assertEqual(expected_output, real_output)

def test_get_client_version_for_java(self):
Expand Down Expand Up @@ -366,33 +366,33 @@ def test_get_client_version_for_stack(self):
def test_get_client_version_for_mozilla(self):
expected_output = "5.0"
real_output = ProcessAccessRecords.get_client_version("WEB", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36")
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36")
self.assertEqual(expected_output, real_output)

def test_get_client_version_for_opera(self):
expected_output = "9.80"
real_output = ProcessAccessRecords.get_client_version("WEB",
"Opera/9.80 (Windows NT 6.1; U; zh-cn) Presto/2.6.37 Version/11.0")
"Opera/9.80 (Windows NT 6.1; U; zh-cn) Presto/2.6.37 Version/11.0")
self.assertEqual(expected_output, real_output)

def test_get_client_version_for_lynx(self):
expected_output = "2.8.5rel.5"
real_output = ProcessAccessRecords.get_client_version("WEB",
"Lynx/2.8.5rel.5 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.8e")
"Lynx/2.8.5rel.5 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.8e")
self.assertEqual(expected_output, real_output)

def test_get_client_version_for_ucweb(self):
expected_output = "2.0"
real_output = ProcessAccessRecords.get_client_version("WEB",
"UCWEB/2.0 (MIDP-2.0; U; Adr 4.4.4; en-US; SM-G360H)"
" U2/1.0.0 UCBrowser/10.9.0.946 U2/1.0.0 Mobile")
"UCWEB/2.0 (MIDP-2.0; U; Adr 4.4.4; en-US; SM-G360H)"
" U2/1.0.0 UCBrowser/10.9.0.946 U2/1.0.0 Mobile")
self.assertEqual(expected_output, real_output)

def test_get_client_version_for_chromium(self):
expected_output = "5.0"
real_output = ProcessAccessRecords.get_client_version("WEB",
"Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 "
"(KHTML, like Gecko) Ubuntu Chromium/115.0.5805.207 Chrome/115.0.5805.207 Safari/537.36")
"Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 "
"(KHTML, like Gecko) Ubuntu Chromium/115.0.5805.207 Chrome/115.0.5805.207 Safari/537.36")
self.assertEqual(expected_output, real_output)

def test_get_client_version_for_chrome(self):
Expand All @@ -402,12 +402,12 @@ def test_get_client_version_for_chrome(self):
def test_get_client_version_for_safari(self):
expected_output = "15609.4.1"
real_output = ProcessAccessRecords.get_client_version("WEB",
"Safari/15609.4.1 CFNetwork/1128.0.1 Darwin/19.6.0 (x86_64)")
"Safari/15609.4.1 CFNetwork/1128.0.1 Darwin/19.6.0 (x86_64)")
self.assertEqual(expected_output, real_output)

def test_get_client_version_for_unknown(self):
real_output = ProcessAccessRecords.get_client_version("UNKNOWN",
"AwarioSmartBot/1.0 (+https://awario.com/bots.html; [email protected])")
"AwarioSmartBot/1.0 (+https://awario.com/bots.html; [email protected])")
self.assertIsNone(real_output)

def test_get_client_version_for_none_client(self):
Expand All @@ -419,12 +419,12 @@ def test_get_client_version_for_none_agent(self):
self.assertIsNone(real_output)

def test_get_entity_id_for_syn_id(self):
expected_output = "12223809"
expected_output = 12223809
real_output = ProcessAccessRecords.get_entity_id("/repo/v1/entity/syn12223809")
self.assertEqual(expected_output, real_output)

def test_get_entity_id_for_id_without_syn(self):
expected_output = "1234"
expected_output = 1234
real_output = ProcessAccessRecords.get_entity_id("/repo/v1/entity/1234")
self.assertEqual(expected_output, real_output)

Expand All @@ -437,16 +437,25 @@ def test_get_entity_id_with_none(self):
self.assertIsNone(real_output)

def test_get_entity_id_for_url_having_two_syn(self):
expected_output = "1234"
expected_output = 1234
real_output = ProcessAccessRecords.get_entity_id("/repo/v1/entity/syn1234/check/syn123456")
self.assertEqual(expected_output, real_output)

def test_get_entity_id_for_case_insensitive(self):
expected_output = "1234"
expected_output = 1234
real_output = ProcessAccessRecords.get_entity_id("/repo/v1/entity/Syn1234/check")
self.assertEqual(expected_output, real_output)

def test_get_entity_id_for_with_version(self):
expected_output = "12345"
expected_output = 12345
real_output = ProcessAccessRecords.get_entity_id("/repo/v1/entity/SYN12345.1/check")
self.assertEqual(expected_output, real_output)

def test_get_entity_id_for_large_value(self):
real_output = ProcessAccessRecords.get_entity_id("/repo/v1/entity/syn22222222222222222222222222/check")
self.assertIsNone(real_output)

def test_get_entity_id_for_sys_maxsize(self):
expected_output = sys.maxsize
real_output = ProcessAccessRecords.get_entity_id("/repo/v1/entity/syn" + str(sys.maxsize) + "/check")
self.assertEqual(expected_output, real_output)

0 comments on commit f350c40

Please sign in to comment.