Skip to content

Commit

Permalink
Merge pull request #635 from ninoseki/add-enable-refang-option
Browse files Browse the repository at this point in the history
feat: add "enable refang" option
  • Loading branch information
ninoseki authored Jan 27, 2022
2 parents d80226f + 13290f6 commit e9635de
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 32 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@github/mini-throttle": "^2.1.0",
"axios": "^0.25.0",
"bulma": "^0.9.3",
"ioc-extractor": "4.0.2",
"ioc-extractor": "4.0.4",
"js-base64": "^3.7.2",
"js-sha256": "^0.9.0",
"mustache": "^4.2.0",
Expand Down
1 change: 1 addition & 0 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export async function createContextMenus(
const selector: Selector = new Selector(text, {
enableIDN: generalSettings.enableIDN,
strictTLD: generalSettings.strictTLD,
enableRefang: generalSettings.enableRefang,
});
// create searchers context menus based on a type of the input
const searcherEntries: AnalyzerEntry[] = selector.getSearcherEntries();
Expand Down
4 changes: 4 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ export async function saveGeneralSettings(): Promise<void> {
const strictTLDInput = document.getElementById(
"strict-tld"
) as HTMLInputElement;
const enableRefangInput = document.getElementById(
"enable-refang"
) as HTMLInputElement;

const generalSettings: GeneralSettings = {
enableIDN: enableIDNInput.checked,
strictTLD: strictTLDInput.checked,
enableRefang: enableRefangInput.checked,
};

await browser.storage.sync.set({ generalSettings });
Expand Down
12 changes: 12 additions & 0 deletions src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ <h2 class="title is-2">Searcher settings</h2>
<label>Enable</label>
</div>
</div>

<div class="field has-addons">
<div class="control is-expanded">
<label class="label">
Enable refang
</label>
</div>
<div class="control">
<input id="enable-refang" type="checkbox" {{#enableRefang}}checked="checked"{{/enableRefang}}>
<label>Enable</label>
</div>
</div>
</script>
</body>

Expand Down
4 changes: 2 additions & 2 deletions src/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export class Selector {

public constructor(
input: string,
options: Options = { enableIDN: true, strictTLD: true }
options: Options = { enableIDN: true, strictTLD: true, enableRefang: true }
) {
this.input = refang(input);
this.input = options.enableRefang ? refang(input) : input;
this.options = options;
}

Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface ScannerTable {
export interface GeneralSettings {
enableIDN: boolean;
strictTLD: boolean;
enableRefang: boolean;
}

export interface Config {
Expand All @@ -112,4 +113,5 @@ export const SHA256_LENGTH = 64;
export interface Options {
enableIDN: boolean;
strictTLD: boolean;
enableRefang: boolean;
}
3 changes: 3 additions & 0 deletions src/utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function convertToGeneralSettings(value: StorageValue): GeneralSettings {
const generalSettings: GeneralSettings = {
enableIDN: false,
strictTLD: false,
enableRefang: false,
};

if (hasGeneralSettings) {
Expand All @@ -44,6 +45,8 @@ function convertToGeneralSettings(value: StorageValue): GeneralSettings {
_generalSettings.enableIDN || generalSettings.enableIDN;
generalSettings.strictTLD =
_generalSettings.strictTLD || generalSettings.strictTLD;
generalSettings.enableRefang =
_generalSettings.enableRefang || generalSettings.enableRefang;
}
return generalSettings;
}
Expand Down
2 changes: 1 addition & 1 deletion test/backgroud.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe("Background script", function () {
await createContextMenus(
{ request: "updateContextMenu", selection: "test" },
{},
{ enableIDN: true, strictTLD: true }
{ enableIDN: true, strictTLD: true, enableRefang: true }
);

browserMock.contextMenus.create.assertNoCall();
Expand Down
15 changes: 13 additions & 2 deletions test/options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ describe("Options script", function () {
);
stub.withArgs("enable-idn").returns(input);
stub.withArgs("strict-tld").returns(input);
stub.withArgs("enable-refang").returns(input);
});

it("should save generalSettings via chrome.storage.sync.set", async function () {
Expand All @@ -122,6 +123,7 @@ describe("Options script", function () {
generalSettings: {
enableIDN: true,
strictTLD: true,
enableRefang: true,
},
},
],
Expand Down Expand Up @@ -215,7 +217,7 @@ describe("Options script", function () {
});
});

it("should compose a searcerList based on searcherStates via chrome.storage.sync.get", async function () {
it("should compose a searcherList based on searcherStates via chrome.storage.sync.get", async function () {
sandbox
.stub(browserMock.storage.sync, "get")
.withArgs("searcherStates")
Expand Down Expand Up @@ -307,7 +309,10 @@ describe("Options script", function () {
);
stub.withArgs("general-settings").returns(wrapper);
stub.withArgs("general-settings-template").returns({
innerHTML: `<input id="enable-idn" type="checkbox" {{#enableIDN}}checked="checked"{{/enableIDN}}><input id="strict-tld" type="checkbox" {{#strictTLD}}checked="checked"{{/strictTLD}}>`,
innerHTML: `
<input id="enable-idn" type="checkbox" {{#enableIDN}}checked="checked"{{/enableIDN}}>
<input id="strict-tld" type="checkbox" {{#strictTLD}}checked="checked"{{/strictTLD}}>
<input id="enable-refang" type="checkbox" {{#enableRefang}}checked="checked"{{/enableRefang}}>`,
});
});

Expand All @@ -319,6 +324,7 @@ describe("Options script", function () {
generalSettings: {
enableIDN: true,
strictTLD: true,
enableRefang: true,
},
});

Expand All @@ -337,6 +343,11 @@ describe("Options script", function () {
"input#strict-tld"
) as HTMLInputElement;
expect(strictTLD.checked).to.equal(true);

const enableRefang = generalSettings.querySelector(
"input#enable-refang"
) as HTMLInputElement;
expect(enableRefang.checked).to.equal(true);
});
});
});
60 changes: 41 additions & 19 deletions test/selector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function numberOfSelectorsByType(type: SearchableType): number {
).length;
}

describe("Seletor", function () {
describe("Selector", function () {
const stats = {
asn: numberOfSelectorsByType("asn"),
btc: numberOfSelectorsByType("btc"),
Expand All @@ -38,13 +38,13 @@ describe("Seletor", function () {
});
});

describe("#getSearchersForIP", function () {
describe("#getSearchersByType with ip", function () {
it("should return searchers which support ip", function () {
expect(selector.getSearchersByType("ip").length).to.equal(stats.ip);
});
});

describe("#getAnalyzerEntrys", function () {
describe("#getSearcherEntries", function () {
it("should return entries which support ip", function () {
const entries: AnalyzerEntry[] = selector.getSearcherEntries();
for (const entry of entries) {
Expand All @@ -65,7 +65,7 @@ describe("Seletor", function () {
});
});

describe("#getSearchersForDomain", function () {
describe("#getSearchersByType with domain", function () {
it("should return searchers which support domain", function () {
expect(selector.getSearchersByType("domain").length).to.equal(
stats.domain
Expand Down Expand Up @@ -93,7 +93,7 @@ describe("Seletor", function () {
});
});

describe("#getSearchersForUrl", function () {
describe("#getSearchersByType with url", function () {
it("should return searchers which support url", function () {
expect(selector.getSearchersByType("url").length).to.equal(stats.url);
});
Expand All @@ -119,15 +119,15 @@ describe("Seletor", function () {
});
});

describe("#getSearchersForEmail", function () {
describe("#getSearchersByType with email", function () {
it("should return searchers which support email", function () {
expect(selector.getSearchersByType("email").length).to.equal(
stats.email
);
});
});

describe("#getAnalyzerEntrys", function () {
describe("#getSearcherEntries", function () {
it("should return entries which support email", function () {
const entries: AnalyzerEntry[] = selector.getSearcherEntries();
for (const entry of entries) {
Expand All @@ -147,13 +147,13 @@ describe("Seletor", function () {
});
});

describe("#getSearchersForASN", function () {
describe("#getSearchersByType with asn", function () {
it("should return searchers which support asn", function () {
expect(selector.getSearchersByType("asn").length).to.equal(stats.asn);
});
});

describe("#getAnalyzerEntrys", function () {
describe("#getSearcherEntries", function () {
it("should return entries which support asn", function () {
const entries: AnalyzerEntry[] = selector.getSearcherEntries();
for (const entry of entries) {
Expand Down Expand Up @@ -184,15 +184,15 @@ describe("Seletor", function () {
});
});

describe("#getSearchersForHash", function () {
describe("#getSearchersByType with hash", function () {
it("should return searchers which support hash", function () {
expect(selector.getSearchersByType("hash").length).to.equal(
stats.hash
);
});
});

describe("#getAnalyzerEntrys", function () {
describe("#getSearcherEntries", function () {
it("should return entries which support hash", function () {
const entries: AnalyzerEntry[] = selector.getSearcherEntries();
for (const entry of entries) {
Expand All @@ -212,13 +212,13 @@ describe("Seletor", function () {
});
});

describe("#getSearchersForCVE", function () {
describe("#getSearchersByType with cve", function () {
it("should return searchers which support CVE", function () {
expect(selector.getSearchersByType("cve").length).to.equal(stats.cve);
});
});

describe("#getAnalyzerEntrys", function () {
describe("#getSearcherEntries", function () {
it("should return entries which support cve", function () {
const entries: AnalyzerEntry[] = selector.getSearcherEntries();
for (const entry of entries) {
Expand All @@ -238,13 +238,13 @@ describe("Seletor", function () {
});
});

describe("#getSearchersForBTC", function () {
describe("#getSearchersByType with btc", function () {
it("should return searchers which support BTC", function () {
expect(selector.getSearchersByType("btc").length).to.equal(stats.btc);
});
});

describe("#getAnalyzerEntrys", function () {
describe("#getSearcherEntries", function () {
it("should return entries which support btc", function () {
const entries: AnalyzerEntry[] = selector.getSearcherEntries();
for (const entry of entries) {
Expand All @@ -264,7 +264,7 @@ describe("Seletor", function () {
});
});

describe("#getSearchersForGATrackID", function () {
describe("#getSearchersByType with gaTrackID", function () {
it("should return searchers which support GATrackID", function () {
expect(selector.getSearchersByType("gaTrackID").length).to.equal(
stats.gaTrackID
Expand All @@ -282,7 +282,7 @@ describe("Seletor", function () {
});
});

describe("#getSearchersForGAPubID", function () {
describe("#getSearchersByType with gaPubID", function () {
it("should return searchers support GAPubID", function () {
expect(selector.getSearchersByType("gaPubID").length).to.equal(
stats.gaPubID
Expand All @@ -300,13 +300,13 @@ describe("Seletor", function () {
});
});

describe("#getSearchersForETH", function () {
describe("#getSearchersByType with eth", function () {
it("should return searchers which support ETH", function () {
expect(selector.getSearchersByType("eth").length).to.equal(stats.eth);
});
});

describe("#getAnalyzerEntrys", function () {
describe("#getSearcherEntries", function () {
it("should return entries which support ETH", function () {
const entries: AnalyzerEntry[] = selector.getSearcherEntries();
for (const entry of entries) {
Expand All @@ -316,5 +316,27 @@ describe("Seletor", function () {
});
});
});

context("without refang", function () {
const ip = "1[.]1.1.1";
const selector: Selector = new Selector(ip, {
enableIDN: true,
strictTLD: true,
enableRefang: false,
});

describe("#getIP", function () {
it("should return null", function () {
expect(selector.getIP()).to.equal(null);
});
});

describe("#getSearcherEntries", function () {
it("should return an empty array", function () {
const entries: AnalyzerEntry[] = selector.getSearcherEntries();
expect(entries.length).to.equal(0);
});
});
});
});
});

0 comments on commit e9635de

Please sign in to comment.