aboutsummaryrefslogtreecommitdiff
path: root/test/shared/blacklists.test.ts
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2019-04-30 14:00:07 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2019-05-02 11:14:19 +0900
commitc60d0e7392fc708e961614d6b756a045de74f458 (patch)
tree0b9a5fce1879e38a92d5dbb2915779aee0ad22d6 /test/shared/blacklists.test.ts
parent257162e5b6b4993e1dff0d705ffa6f0d809033eb (diff)
Rename .js/.jsx to .ts/.tsx
Diffstat (limited to 'test/shared/blacklists.test.ts')
-rw-r--r--test/shared/blacklists.test.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/shared/blacklists.test.ts b/test/shared/blacklists.test.ts
new file mode 100644
index 0000000..289ea0f
--- /dev/null
+++ b/test/shared/blacklists.test.ts
@@ -0,0 +1,49 @@
+import { includes } from 'shared/blacklists';
+
+describe("shared/blacklist", () => {
+ it('matches by *', () => {
+ let blacklist = ['*'];
+
+ expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
+ })
+
+ it('matches by hostname', () => {
+ let blacklist = ['github.com'];
+
+ expect(includes(blacklist, 'https://github.com')).to.be.true;
+ expect(includes(blacklist, 'https://gist.github.com')).to.be.false;
+ expect(includes(blacklist, 'https://github.com/ueokande')).to.be.true;
+ expect(includes(blacklist, 'https://github.org')).to.be.false;
+ expect(includes(blacklist, 'https://google.com/search?q=github.org')).to.be.false;
+ })
+
+ it('matches by hostname with wildcard', () => {
+ let blacklist = ['*.github.com'];
+
+ expect(includes(blacklist, 'https://github.com')).to.be.false;
+ expect(includes(blacklist, 'https://gist.github.com')).to.be.true;
+ })
+
+ it('matches by path', () => {
+ let blacklist = ['github.com/abc'];
+
+ expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
+ expect(includes(blacklist, 'https://github.com/abcdef')).to.be.false;
+ expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false;
+ })
+
+ it('matches by path with wildcard', () => {
+ let blacklist = ['github.com/abc*'];
+
+ expect(includes(blacklist, 'https://github.com/abc')).to.be.true;
+ expect(includes(blacklist, 'https://github.com/abcdef')).to.be.true;
+ expect(includes(blacklist, 'https://gist.github.com/abc')).to.be.false;
+ })
+
+ it('matches address and port', () => {
+ let blacklist = ['127.0.0.1:8888'];
+
+ expect(includes(blacklist, 'http://127.0.0.1:8888/')).to.be.true;
+ expect(includes(blacklist, 'http://127.0.0.1:8888/hello')).to.be.true;
+ })
+});