From 0078e0bf5b86fb037c1e1a1844fdad9be04f907a Mon Sep 17 00:00:00 2001 From: giwawayu <162892865+giwawayu@users.noreply.github.com> Date: Thu, 28 Mar 2024 21:26:03 +0800 Subject: [PATCH 1/6] Update main_test.js --- lab3/main_test.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/lab3/main_test.js b/lab3/main_test.js index 096fd421..7c5e9bae 100644 --- a/lab3/main_test.js +++ b/lab3/main_test.js @@ -2,4 +2,63 @@ const { describe, it } = require('node:test'); const assert = require('assert'); const { Calculator } = require('./main'); -// TODO: write your tests here +describe("Calculator Test", () => { + const calculator = new Calculator(); + + const logTestSuites = [ + { + operation: "log", + cases: [ + { data: 6, expected: Math.log(6) }, + { data: 5, expected: Math.log(5) }, + { data: 2, expected: Math.log(2) }, + { data: 'guava', expected: Error, message: "unsupported operand type" }, + { data: true, expected: Error, message: "unsupported operand type" }, + { data: Infinity, expected: Error, message: "unsupported operand type" }, + { data: 0, expected: Error, message: "math domain error (1)" }, + { data: -1, expected: Error, message: "math domain error (2)" }, + ] + } + ]; + + logTestSuites.forEach(({ operation, cases }) => { + it(`Calculator.${operation}() Test`, () => { + cases.forEach(({ data: param, expected: expectedOutput, message: msg }) => { + if (expectedOutput === Error) { + assert.throws(() => calculator[operation](param), expectedOutput, msg); + } else { + const result = calculator[operation](param); + assert.strictEqual(result, expectedOutput, msg); + } + }); + }); + }); + + const expTestSuites = [ + { + operation: "exp", + cases: [ + { data: 4, expected: Math.exp(4) }, + { data: 0, expected: Math.exp(0) }, + { data: -2, expected: Math.exp(-2) }, + { data: 'guava666', expected: Error, message: "unsupported operand type" }, + { data: true, expected: Error, message: "unsupported operand type" }, + { data: Infinity, expected: Error, message: "unsupported operand type" }, + { data: Number.MAX_VALUE, expected: Error, message: "overflow" }, + ] + } + ]; + + expTestSuites.forEach(({ operation, cases }) => { + it(`Calculator.${operation}() Test`, () => { + cases.forEach(({ data: param, expected: expectedOutput, message: msg }) => { + if (expectedOutput === Error) { + assert.throws(() => calculator[operation](param), expectedOutput, msg); + } else { + const result = calculator[operation](param); + assert.strictEqual(result, expectedOutput, msg); + } + }); + }); + }); +}); From e19b9f55212cc8f72c1aaa7bdd924aa5f9f8795c Mon Sep 17 00:00:00 2001 From: giwawayu <162892865+giwawayu@users.noreply.github.com> Date: Thu, 4 Apr 2024 23:58:08 +0800 Subject: [PATCH 2/6] Update main_test.js --- lab4/main_test.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lab4/main_test.js b/lab4/main_test.js index e37d21a5..cda7dfef 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -10,13 +10,25 @@ const puppeteer = require('puppeteer'); // Hints: // Click search button + await page.click('button.DocSearch.DocSearch-Button'); //點擊指定按鈕 + // Type into search box // Wait for search result + await page.waitForSelector('#docsearch-input.DocSearch-Input'); //等待 id 為 docsearch-input 且具有 DocSearch-Input 類的元素出現在頁面上 + await page.type('#docsearch-input.DocSearch-Input', 'chipi chipi chapa chapa',{delay: 2000}); //將指定的文字 'chipi chipi chapa chapa' 輸入到 id 為 docsearch-input 且具有 DocSearch-Input 類的元素中 + // Get the `Docs` result section + await page.waitForSelector('#docsearch-item-5.DocSearch-Hit'); //等待 id 為 docsearch-item-5 且具有 DocSearch-Hit 類的元素出現在頁面上 // Click on first result in `Docs` section + await page.click('#docsearch-item-5.DocSearch-Hit'); //點擊指定按鈕 + // Locate the title + let titletext = await page.waitForSelector('#__docusaurus_skipToContent_fallback > div > div > main > div > div > div > div > article > div.theme-doc-markdown.markdown > h1'); //等待指定的元素出現在當前頁面上,並將內容存儲在變數 titletext 中 + let flag = await titletext.evaluate(element=> element.textContent); //使用 textContent 屬性來獲取指定文字內容 + // Print the title - + console.log(flag); //呈現指定內容 + // Close the browser await browser.close(); -})(); \ No newline at end of file +})(); From 30a612e14f449b3e735d337a5d5f1f556a8aebf1 Mon Sep 17 00:00:00 2001 From: giwawayu <162892865+giwawayu@users.noreply.github.com> Date: Thu, 4 Apr 2024 23:58:38 +0800 Subject: [PATCH 3/6] Update main_test.js --- lab4/main_test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lab4/main_test.js b/lab4/main_test.js index cda7dfef..706f01d2 100644 --- a/lab4/main_test.js +++ b/lab4/main_test.js @@ -7,7 +7,7 @@ const puppeteer = require('puppeteer'); // Navigate the page to a URL await page.goto('https://pptr.dev/'); - + // Hints: // Click search button await page.click('button.DocSearch.DocSearch-Button'); //點擊指定按鈕 From 20d98f38708f7106b0a90e903f291d4810e9a608 Mon Sep 17 00:00:00 2001 From: giwawayu <162892865+giwawayu@users.noreply.github.com> Date: Tue, 28 May 2024 20:52:28 +0800 Subject: [PATCH 4/6] Update sol.py --- lab7/sol.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lab7/sol.py b/lab7/sol.py index e69de29b..222bdd6f 100644 --- a/lab7/sol.py +++ b/lab7/sol.py @@ -0,0 +1,13 @@ +import angr, sys +proj = angr.Project('./login') +init_state = proj.factory.entry_state() +simulation = proj.factory.simgr(init_state) +simulation.explore(find=success_condition, avoid=fail_condition) +def success_condition(state): + return b'Login successful' in state.posix.dumps(sys.stdout.fileno()) +def fail_condition(state): + return b'Login failed' in state.posix.dumps(sys.stdout.fileno()) + +simulation.explore(find=success_condition, avoid=fail_condition) +solution = simulation.found[0] +print(solution.posix.dumps(sys.stdin.fileno())) From aaa08b781a0b68dceabc353cd3cf112ef83a2963 Mon Sep 17 00:00:00 2001 From: giwawayu <162892865+giwawayu@users.noreply.github.com> Date: Tue, 28 May 2024 20:55:07 +0800 Subject: [PATCH 5/6] Update sol.py --- lab7/sol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lab7/sol.py b/lab7/sol.py index 222bdd6f..f38c4adb 100644 --- a/lab7/sol.py +++ b/lab7/sol.py @@ -2,7 +2,7 @@ proj = angr.Project('./login') init_state = proj.factory.entry_state() simulation = proj.factory.simgr(init_state) -simulation.explore(find=success_condition, avoid=fail_condition) + def success_condition(state): return b'Login successful' in state.posix.dumps(sys.stdout.fileno()) def fail_condition(state): From 15fc77985e2e25db474d2d0915a5f3fbccc13a25 Mon Sep 17 00:00:00 2001 From: giwawayu <162892865+giwawayu@users.noreply.github.com> Date: Tue, 28 May 2024 20:56:56 +0800 Subject: [PATCH 6/6] Update sol.py --- lab7/sol.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lab7/sol.py b/lab7/sol.py index f38c4adb..55c4a6b5 100644 --- a/lab7/sol.py +++ b/lab7/sol.py @@ -1,12 +1,15 @@ -import angr, sys +import angr +import sys + proj = angr.Project('./login') init_state = proj.factory.entry_state() simulation = proj.factory.simgr(init_state) def success_condition(state): - return b'Login successful' in state.posix.dumps(sys.stdout.fileno()) + return b"Login successful" in state.posix.dumps(sys.stdout.fileno()) + def fail_condition(state): - return b'Login failed' in state.posix.dumps(sys.stdout.fileno()) + return b"Login failed" in state.posix.dumps(sys.stdout.fileno()) simulation.explore(find=success_condition, avoid=fail_condition) solution = simulation.found[0]