diff options
author | Matthew Shao <me@matshao.com> | 2017-04-26 17:06:50 +0800 |
---|---|---|
committer | Matthew Shao <me@matshao.com> | 2017-04-26 17:06:50 +0800 |
commit | ec7d90f9be1dca8a989da2696df1bba223c01364 (patch) | |
tree | a17f4b79a0d62565d92be018e8a756135ba29788 /web/src/js/__tests__/flow/utilsSpec.js | |
parent | e32efcae49ba5857feae85b9b4651a45d9e5fcc3 (diff) | |
download | mitmproxy-ec7d90f9be1dca8a989da2696df1bba223c01364.tar.gz mitmproxy-ec7d90f9be1dca8a989da2696df1bba223c01364.tar.bz2 mitmproxy-ec7d90f9be1dca8a989da2696df1bba223c01364.zip |
[web] Add coverage for js/utils.js, js/flow/utils.js
Diffstat (limited to 'web/src/js/__tests__/flow/utilsSpec.js')
-rw-r--r-- | web/src/js/__tests__/flow/utilsSpec.js | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/web/src/js/__tests__/flow/utilsSpec.js b/web/src/js/__tests__/flow/utilsSpec.js new file mode 100644 index 00000000..2d8f0456 --- /dev/null +++ b/web/src/js/__tests__/flow/utilsSpec.js @@ -0,0 +1,69 @@ +import * as utils from '../../flow/utils' + +describe('MessageUtils', () => { + it('should be possible to get first header', () => { + let msg = { headers: [["foo", "bar"]]} + expect(utils.MessageUtils.get_first_header(msg, "foo")).toEqual("bar") + expect(utils.MessageUtils.get_first_header(msg, "123")).toEqual(undefined) + }) + + it('should be possible to get Content-Type', () => { + let type = "text/html", + msg = { headers: [["Content-Type", type]]} + expect(utils.MessageUtils.getContentType(msg)).toEqual(type) + }) + + it('should be possible to match header', () => { + let h1 = ["foo", "bar"], + msg = {headers : [h1]} + expect(utils.MessageUtils.match_header(msg, /foo/i)).toEqual(h1) + expect(utils.MessageUtils.match_header(msg, /123/i)).toBeFalsy() + }) + + it('should be possible to get content URL', () => { + // request + let msg = "foo", view = "bar", + flow = { request: msg, id: 1} + expect(utils.MessageUtils.getContentURL(flow, msg, view)).toEqual( + "/flows/1/request/content/bar" + ) + expect(utils.MessageUtils.getContentURL(flow, msg, '')).toEqual( + "/flows/1/request/content" + ) + // response + flow = {response: msg, id: 2} + expect(utils.MessageUtils.getContentURL(flow, msg, view)).toEqual( + "/flows/2/response/content/bar" + ) + }) +}) + +describe('RequestUtils', () => { + it('should be possible prettify url', () => { + let request = {port: 4444, scheme: "http", pretty_host: "foo", path: "/bar"} + expect(utils.RequestUtils.pretty_url(request)).toEqual( + "http://foo:4444/bar" + ) + }) +}) + +describe('parseUrl', () => { + it('should be possible to parse url', () => { + let url = "http://foo:4444/bar" + expect(utils.parseUrl(url)).toEqual({ + port: 4444, + scheme: 'http', + host: 'foo', + path: '/bar' + }) + + expect(utils.parseUrl("foo:foo")).toBeFalsy() + }) +}) + +describe('isValidHttpVersion', () => { + it('should be possible to validate http version', () => { + expect(utils.isValidHttpVersion("HTTP/1.1")).toBeTruthy() + expect(utils.isValidHttpVersion("HTTP//1")).toBeFalsy() + }) +}) |