diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-04-26 13:38:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-26 13:38:54 +0200 |
commit | cef01ac1647492a40bccb362237a2eac93e29e31 (patch) | |
tree | d6c1219402cd0d4afa0652d7588cb0a09b0e94c7 /web/src/js/__tests__/flow/utilsSpec.js | |
parent | 7607240c30a319f37494baeca07ff735289d0315 (diff) | |
parent | ec7d90f9be1dca8a989da2696df1bba223c01364 (diff) | |
download | mitmproxy-cef01ac1647492a40bccb362237a2eac93e29e31.tar.gz mitmproxy-cef01ac1647492a40bccb362237a2eac93e29e31.tar.bz2 mitmproxy-cef01ac1647492a40bccb362237a2eac93e29e31.zip |
Merge pull request #2267 from MatthewShao/jest-dev
[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() + }) +}) |