From 54501afb1fa54c32dc06cec6a7f18690710a8855 Mon Sep 17 00:00:00 2001 From: liujayo <37663339+toey8612@users.noreply.github.com> Date: Wed, 17 Apr 2024 08:31:26 +0800 Subject: [PATCH 1/6] Update main_test.js --- lab3/main_test.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lab3/main_test.js b/lab3/main_test.js index 096fd421..3b22f558 100644 --- a/lab3/main_test.js +++ b/lab3/main_test.js @@ -3,3 +3,50 @@ const assert = require('assert'); const { Calculator } = require('./main'); // TODO: write your tests here + +describe('Calculator', () => { + + describe('exp', () => { + // 檢查 exp 方法在輸入 0、1 和 -1 時。 + it('Calculate correctly', () => { + const calculator = new Calculator(); + assert.strictEqual(calculator.exp(0), 1); + assert.strictEqual(calculator.exp(1), Math.exp(1)); + assert.strictEqual(calculator.exp(-1), 1 / Math.exp(1)); + }); + // 檢查 exp 方法在Infinity(-) 時。 + it('Calculate error', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.exp(NaN), Error); + assert.throws(() => calculator.exp(Infinity), Error); + assert.throws(() => calculator.exp(-Infinity), Error); + }); + // 檢查 exp 方法在 overflow 時。 + it('overflows', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.exp(9999), Error); + }); + }); + + describe('log', () => { + // 檢查 log 方法在輸入 1 和 Math.E 時 + it('calculate orrectly', () => { + const calculator = new Calculator(); + assert.strictEqual(calculator.log(1), 0); + assert.strictEqual(calculator.log(Math.E), 1); + }); + //檢查 log 方法在輸入 NaN、Infinity時 + it('Calculate error', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.log(NaN), Error); + assert.throws(() => calculator.log(Infinity), Error); + assert.throws(() => calculator.log(-Infinity), Error); + }); + // 檢查 log 方法在輸入 0 和 -1 時 + it('negative infinity or NaN', () => { + const calculator = new Calculator(); + assert.throws(() => calculator.log(0), Error); + assert.throws(() => calculator.log(-1), Error); + }); + }); +}); From 9f5f9f427e188411f9949238ce6ff410f4e7a846 Mon Sep 17 00:00:00 2001 From: liujayo <37663339+toey8612@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:27:40 +0800 Subject: [PATCH 2/6] Update main_test.js --- lab4/main_test.js | 50 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a5..249841e6 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -1,22 +1,44 @@ const puppeteer = require('puppeteer'); (async () => { - // Launch the browser and open a new blank page + // 啟動瀏覽器並打開一個新的空白頁面 const browser = await puppeteer.launch(); const page = await browser.newPage(); + try{ + // 導航至指定網址 + await page.goto('https://pptr.dev/'); + await new Promise(resolve => setTimeout(resolve, 1000)); - // Navigate the page to a URL - await page.goto('https://pptr.dev/'); + // 點擊搜尋按鈕 + await page.click('button.DocSearch.DocSearch-Button'); + await new Promise(resolve => setTimeout(resolve, 1000)); - // Hints: - // Click search button - // Type into search box - // Wait for search result - // Get the `Docs` result section - // Click on first result in `Docs` section - // Locate the title - // Print the title + // 在搜尋框中輸入文字 + await page.waitForSelector('#docsearch-input'); + await page.type('#docsearch-input', 'chipi chipi chapa chapa', { delay: 1000 }); + await new Promise(resolve => setTimeout(resolve, 1000)); - // Close the browser - await browser.close(); -})(); \ No newline at end of file + // 等待搜尋結果 + await page.waitForSelector('#docsearch-item-5'); + await new Promise(resolve => setTimeout(resolve, 1000)); + + // 點擊「Docs」部分的第一個結果 + await page.click('#docsearch-item-5'); + await new Promise(resolve => setTimeout(resolve, 1000)); + + // 定位標題 + await page.waitForSelector('h1'); + + // 獲取標題元素的文字內容 + const title = await page.evaluate(() => { + const titleElement = document.querySelector('h1'); + return titleElement.textContent; + }); + console.log(title); + await browser.close(); + }catch(error){ + console.error('An error occurred:', error); + }finally{ + // 最後都會關閉瀏覽器 + await browser.close();} +})(); From c95ed2fa447a2aad1be05405ed642ad0d74a5df0 Mon Sep 17 00:00:00 2001 From: liujayo <37663339+toey8612@users.noreply.github.com> Date: Wed, 24 Apr 2024 11:45:23 +0800 Subject: [PATCH 3/6] Update main_test.js --- lab4/main_test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lab4/main_test.js b/lab4/main_test.js index 249841e6..1ff2fcf8 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -35,7 +35,6 @@ const puppeteer = require('puppeteer'); return titleElement.textContent; }); console.log(title); - await browser.close(); }catch(error){ console.error('An error occurred:', error); }finally{ From 259ecb6832615c7a0242d674d7caf55bbe82ccf3 Mon Sep 17 00:00:00 2001 From: liujayo <37663339+toey8612@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:13:11 +0800 Subject: [PATCH 4/6] Update main_test.js --- lab4/main_test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lab4/main_test.js b/lab4/main_test.js index 1ff2fcf8..491f0b83 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -7,24 +7,24 @@ const puppeteer = require('puppeteer'); try{ // 導航至指定網址 await page.goto('https://pptr.dev/'); - await new Promise(resolve => setTimeout(resolve, 1000)); + // 點擊搜尋按鈕 await page.click('button.DocSearch.DocSearch-Button'); - await new Promise(resolve => setTimeout(resolve, 1000)); + // 在搜尋框中輸入文字 await page.waitForSelector('#docsearch-input'); await page.type('#docsearch-input', 'chipi chipi chapa chapa', { delay: 1000 }); - await new Promise(resolve => setTimeout(resolve, 1000)); + // 等待搜尋結果 await page.waitForSelector('#docsearch-item-5'); - await new Promise(resolve => setTimeout(resolve, 1000)); + // 點擊「Docs」部分的第一個結果 await page.click('#docsearch-item-5'); - await new Promise(resolve => setTimeout(resolve, 1000)); + // 定位標題 await page.waitForSelector('h1'); From f7cda0d571ee194772174f6757c6d1db2fc15ad9 Mon Sep 17 00:00:00 2001 From: liujayo <37663339+toey8612@users.noreply.github.com> Date: Wed, 22 May 2024 17:07:16 +0800 Subject: [PATCH 5/6] Update Answer.md --- lab6/Answer.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lab6/Answer.md b/lab6/Answer.md index fabc82e6..53b95850 100644 --- a/lab6/Answer.md +++ b/lab6/Answer.md @@ -3,10 +3,55 @@ ID: ### Fuzz Monitor ``` +![image](https://github.com/toey8612/112-spring-software-testing-and-secure-programming/assets/37663339/10627090-66b9-49f5-8c03-887a5d43cbdc) + + american fuzzy lop 2.57b (bmpcomp) + +┌─ process timing ─────────────────────────────────────┬─ overall results ─────┐ +│ run time : 0 days, 0 hrs, 2 min, 2 sec │ cycles done : 0 │ +│ last new path : 0 days, 0 hrs, 0 min, 28 sec │ total paths : 18 │ +│ last uniq crash : 0 days, 0 hrs, 1 min, 54 sec │ uniq crashes : 1 │ +│ last uniq hang : none seen yet │ uniq hangs : 0 │ +├─ cycle progress ────────────────────┬─ map coverage ─┴───────────────────────┤ +│ now processing : 0 (0.00%) │ map density : 0.04% / 0.05% │ +│ paths timed out : 0 (0.00%) │ count coverage : 2.12 bits/tuple │ +├─ stage progress ────────────────────┼─ findings in depth ────────────────────┤ +│ now trying : arith 16/8 │ favored paths : 1 (5.56%) │ +│ stage execs : 468/2599 (18.01%) │ new edges on : 4 (22.22%) │ +│ total execs : 2962 │ total crashes : 121 (1 unique) │ +│ exec speed : 44.27/sec (slow!) │ total tmouts : 369 (7 unique) │ +├─ fuzzing strategy yields ───────────┴───────────────┬─ path geometry ────────┤ +│ bit flips : 7/224, 3/223, 1/221 │ levels : 2 │ +│ byte flips : 0/28, 0/27, 0/25 │ pending : 18 │ +│ arithmetics : 7/1565, 0/0, 0/0 │ pend fav : 1 │ +│ known ints : 0/0, 0/0, 0/0 │ own finds : 17 │ +│ dictionary : 0/0, 0/0, 0/0 │ imported : n/a │ +│ havoc : 0/0, 0/0 │ stability : 100.00% │ +│ trim : 100.00%/37, 0.00% ├────────────────────────┘ +└─────────────────────────────────────────────────────┘ [cpu010: 7%] ``` ### Run Crash Result ``` +![image](https://github.com/toey8612/112-spring-software-testing-and-secure-programming/assets/37663339/5e59bd9f-faa3-4384-bfe6-e13a0c8a12f8) ++++ Testing aborted by user +++ +[+] We're done here. Have a nice day! + +(Lab6) liu@MSI:~/112-spring-software-testing-and-secure-programming/lab6/fuzz$ ls out/ +crashes fuzz_bitmap fuzzer_stats hangs plot_data queue +(Lab6) liu@MSI:~/112-spring-software-testing-and-secure-programming/lab6/fuzz$ ls out/crashes/ +README.txt id:000000,sig:06,src:000000,op:flip1,pos:20 +(Lab6) liu@MSI:~/112-spring-software-testing-and-secure-programming/lab6/fuzz$ ../src/bmpcomp . /out/crashes/id\:000000,sig:06,src:000000,op:flip1,pos:20 +size of Herder 54 +AddressSanitizer:DEADLYSIGNAL +================================================================= +==208984==ERROR: AddressSanitizer: stack-overflow on address 0x7ffd201229f8 (pc 0x556e8c08f11f bp 0x7ffd20920e50 sp 0x7ffd20121a00 T0) + #0 0x556e8c08f11f in main /home/liu/112-spring-software-testing-and-secure-programming/lab6/src/hw0302.c:46 + #1 0x7f037a105d8f (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) + #2 0x7f037a105e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) + #3 0x556e8c08fc24 in _start (/home/liu/112-spring-software-testing-and-secure-programming/lab6/src/bmpcomp+0x2c24) +SUMMARY: AddressSanitizer: stack-overflow /home/liu/112-spring-software-testing-and-secure-programming/lab6/src/hw0302.c:46 in main +==208984==ABORTING ``` From 8d99b026df1e3af8bbc71e6a5cdbefebfaec7e60 Mon Sep 17 00:00:00 2001 From: liujayo <37663339+toey8612@users.noreply.github.com> Date: Wed, 22 May 2024 17:08:02 +0800 Subject: [PATCH 6/6] Update Answer.md --- lab6/Answer.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lab6/Answer.md b/lab6/Answer.md index 53b95850..10d3cd63 100644 --- a/lab6/Answer.md +++ b/lab6/Answer.md @@ -1,10 +1,8 @@ -Name: -ID: +Name: 劉珈佑 +ID: 511558020 ### Fuzz Monitor ``` -![image](https://github.com/toey8612/112-spring-software-testing-and-secure-programming/assets/37663339/10627090-66b9-49f5-8c03-887a5d43cbdc) - american fuzzy lop 2.57b (bmpcomp) ┌─ process timing ─────────────────────────────────────┬─ overall results ─────┐ @@ -34,7 +32,6 @@ ID: ### Run Crash Result ``` -![image](https://github.com/toey8612/112-spring-software-testing-and-secure-programming/assets/37663339/5e59bd9f-faa3-4384-bfe6-e13a0c8a12f8) +++ Testing aborted by user +++ [+] We're done here. Have a nice day!