Best Python code snippet using tempest_python
test_sections_api.py
Source: test_sections_api.py
...17 assert boot_section.uid == 018 assert not boot_section.is_last19 assert boot_section.hmac_count == 120 assert boot_section.raw_size == 14421 dek = crypto_backend().random_bytes(32)22 mac = crypto_backend().random_bytes(32)23 nonce = crypto_backend().random_bytes(16)24 data = boot_section.export(dek, mac, Counter(nonce))25 assert data26 assert BootSectionV2.parse(data, 0, False, dek, mac, Counter(nonce))27 with pytest.raises(SPSDKError, match="Invalid type of dek, should be bytes"):28 BootSectionV2.parse(29 data=data, offset=0, plain_sect=False, dek=4, mac=mac, counter=Counter(nonce)30 )31 with pytest.raises(SPSDKError, match="Invalid type of mac, should be bytes"):32 BootSectionV2.parse(33 data=data, offset=0, plain_sect=False, dek=dek, mac=4, counter=Counter(nonce)34 )35 with pytest.raises(SPSDKError, match="Invalid type of counter"):36 BootSectionV2.parse(data=data, offset=0, plain_sect=False, dek=dek, mac=mac, counter=5)37 with pytest.raises(SPSDKError):38 assert BootSectionV2.parse(39 data, 0, False, dek, crypto_backend().random_bytes(32), Counter(nonce)40 )41def test_boot_section_v2_invalid_export():42 boot_section = BootSectionV2(43 0, CmdErase(address=0, length=100000), CmdLoad(address=0, data=b"0123456789"), CmdReset()44 )45 dek = 3246 mac = 447 nonce = crypto_backend().random_bytes(16)48 with pytest.raises(SPSDKError, match="Invalid type of dek, should be bytes"):49 boot_section.export(dek, mac, Counter(nonce))50 dek = crypto_backend().random_bytes(32)51 with pytest.raises(SPSDKError, match="Invalid type of mac, should be bytes"):52 boot_section.export(dek, mac, Counter(nonce))53 counter = 554 mac = crypto_backend().random_bytes(32)55 with pytest.raises(SPSDKError, match="Invalid type of counter"):56 boot_section.export(dek, mac, counter)57def test_boot_section_v2_raw_size():58 b_section = BootSectionV2(uid=2)59 b_section.HMAC_SIZE = 360 assert b_section.raw_size == 3261def test_boot_section_v2_hmac_count():62 b_section = BootSectionV2(uid=2, hmac_count=0)63 assert b_section.uid == 264def _create_cert_block_v2(data_dir: str) -> CertBlockV2:65 with open(os.path.join(data_dir, "selfsign_v3.der.crt"), "rb") as f:66 cert_data = f.read()67 cb = CertBlockV2()68 cert_obj = Certificate(cert_data)69 cb.set_root_key_hash(0, cert_obj.public_key_hash)70 cb.add_certificate(cert_obj)71 return cb72def test_certificate_section_v2(data_dir: str) -> None:73 with pytest.raises(AssertionError):74 CertSectionV2(None)75 cs = CertSectionV2(_create_cert_block_v2(data_dir))76 dek = crypto_backend().random_bytes(32)77 mac = crypto_backend().random_bytes(32)78 nonce = crypto_backend().random_bytes(16)79 data = cs.export(dek, mac, Counter(nonce))80 assert data81 assert CertSectionV2.parse(data, 0, dek, mac, Counter(nonce))82 with pytest.raises(SPSDKError):83 CertSectionV2.parse(data, 0, dek, crypto_backend().random_bytes(32), Counter(nonce))84def test_invalid_export_cert_section_v2(data_dir):85 cs = CertSectionV2(_create_cert_block_v2(data_dir))86 dek = crypto_backend().random_bytes(16)87 mac = crypto_backend().random_bytes(16)88 nonce = crypto_backend().random_bytes(16)89 cs.HMAC_SIZE = 13790 with pytest.raises(SPSDKError, match="Invalid size"):91 cs.export(dek, mac, Counter(nonce))92def test_certificate_block_v2(data_dir):93 _create_cert_block_v2(data_dir)94def test_invalid_parse_cert_section_v2(data_dir):95 with pytest.raises(SPSDKError):96 CertSectionV2.parse(bytes(123), 0, dek="6")97 with pytest.raises(SPSDKError):98 CertSectionV2.parse(bytes(123), 0, mac="6")99 with pytest.raises(SPSDKError):100 CertSectionV2.parse(bytes(123), 0, counter="6")101def test_invalid_header_hmac(data_dir):102 cs = CertSectionV2(_create_cert_block_v2(data_dir))103 dek = crypto_backend().random_bytes(32)104 mac = crypto_backend().random_bytes(32)105 nonce = crypto_backend().random_bytes(16)106 valid_data = cs.export(dek, mac, Counter(nonce))107 invalid_data = valid_data108 invalid_data = bytearray(invalid_data)109 invalid_data[0:32] = bytearray(32)110 with pytest.raises(SPSDKError, match="HMAC"):111 CertSectionV2.parse(invalid_data, 0, dek, mac, Counter(nonce))112def test_invalid_header_tag(data_dir):113 cs = CertSectionV2(_create_cert_block_v2(data_dir))114 cs._header.tag += 1115 dek = crypto_backend().random_bytes(32)116 mac = crypto_backend().random_bytes(32)117 nonce = crypto_backend().random_bytes(16)118 valid_data = cs.export(dek, mac, Counter(nonce))119 with pytest.raises(SPSDKError, match="TAG"):120 CertSectionV2.parse(data=valid_data, mac=mac, dek=dek, counter=Counter(nonce))121def test_invalid_header_flag(data_dir):122 cs = CertSectionV2(_create_cert_block_v2(data_dir))123 cs._header.flags += 1124 dek = crypto_backend().random_bytes(32)125 mac = crypto_backend().random_bytes(32)126 nonce = crypto_backend().random_bytes(16)127 valid_data = cs.export(dek, mac, Counter(nonce))128 with pytest.raises(SPSDKError, match="FLAGS"):129 CertSectionV2.parse(data=valid_data, mac=mac, dek=dek, counter=Counter(nonce))130def test_invalid_header_flag(data_dir):131 cs = CertSectionV2(_create_cert_block_v2(data_dir))132 cs._header.address += 1133 dek = crypto_backend().random_bytes(32)134 mac = crypto_backend().random_bytes(32)135 nonce = crypto_backend().random_bytes(16)136 valid_data = cs.export(dek, mac, Counter(nonce))137 with pytest.raises(SPSDKError, match="Mark"):138 CertSectionV2.parse(data=valid_data, mac=mac, dek=dek, counter=Counter(nonce))139def test_cert_section(data_dir):140 cs = CertSectionV2(_create_cert_block_v2(data_dir))...
test_writer.py
Source: test_writer.py
...7import random8import string9import tempfile10@pytest.fixture11def random_bytes(size=1024):12 """Return random bytes."""13 return os.urandom(size)14@pytest.fixture15def random_string(size=1024):16 """Return random string."""17 return "".join(random.choices(string.ascii_uppercase + string.digits, k=size))18def is_binary(f):19 """Check if the file object is opened in binary mode or not."""20 return "b" in f.mode21def compare_files(files, hashfunc=hashlib.sha256):22 """Compares the contents of two file objects."""23 digest = None24 for f in files:25 h = hashfunc()...
get_number_of_duplicates.py
Source: get_number_of_duplicates.py
1import pymongo2import secrets3mongoClient = pymongo.MongoClient("mongodb://"+secrets.mongoUsername+":"+secrets.mongoPassword+"@cloud.nds.rub.de:42200"4 "/?authSource=admin")5testDataBase = mongoClient['randomness-test-mix']6randomnessScans = testDataBase['randomness-test-mix-0']7test_filter = {8 'result.report.supportsSslTls': True,9 'result.report.serverIsAlive': None10}11scanEntries = randomnessScans.find(test_filter)12list_of_randoms = set()13list_of_duplicates = dict()14for scan in scanEntries:15 random = scan['result']['report']['extractedRandomList']16 hostname = scan['scanTarget']['hostname']17 if random is not None:18 for rand in random:19 random_bytes = rand.get('array')20 if random_bytes not in list_of_randoms:21 list_of_randoms.add(random_bytes)22 else:23 if random_bytes in list_of_duplicates:24 if hostname not in list_of_duplicates.get(random_bytes):25 list_of_duplicates.get(random_bytes).append(hostname)26 else:27 list_of_duplicates[random_bytes] = [hostname]28testDataBase = mongoClient['randomness-test6']29randomnessScans = testDataBase['randomness-test6-0']30test_filter = {31 'result.report.supportsSslTls': True,32 'result.report.serverIsAlive': None33}34scanEntries = randomnessScans.find(test_filter)35for scan in scanEntries:36 random = scan['result']['report']['extractedRandomList']37 hostname = scan['scanTarget']['hostname']38 if random is not None:39 for rand in random:40 random_bytes = rand.get('array')41 if random_bytes not in list_of_randoms:42 list_of_randoms.add(random_bytes)43 else:44 if random_bytes in list_of_duplicates:45 if hostname not in list_of_duplicates.get(random_bytes):46 list_of_duplicates.get(random_bytes).append(hostname)47 else:48 list_of_duplicates[random_bytes] = [hostname]49for random in list_of_duplicates:50 if len(list_of_duplicates[random]) > 1:51 print(random)...
Check out the latest blogs from LambdaTest on this topic:
These days, development teams depend heavily on feedback from automated tests to evaluate the quality of the system they are working on.
I think that probably most development teams describe themselves as being “agile” and probably most development teams have standups, and meetings called retrospectives.There is also a lot of discussion about “agile”, much written about “agile”, and there are many presentations about “agile”. A question that is often asked is what comes after “agile”? Many testers work in “agile” teams so this question matters to us.
I routinely come across test strategy documents when working with customers. They are lengthy—100 pages or more—and packed with monotonous text that is routinely reused from one project to another. Yawn once more— the test halt and resume circumstances, the defect management procedure, entrance and exit criteria, unnecessary generic risks, and in fact, one often-used model replicates the requirements of textbook testing, from stress to systems integration.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
When working on web automation with Selenium, I encountered scenarios where I needed to refresh pages from time to time. When does this happen? One scenario is that I needed to refresh the page to check that the data I expected to see was still available even after refreshing. Another possibility is to clear form data without going through each input individually.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!