mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
begin snowflake coffee tests and Cakefile
This commit is contained in:
parent
93a9aabfd1
commit
95952830ba
3 changed files with 99 additions and 0 deletions
8
proxy/Cakefile
Normal file
8
proxy/Cakefile
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
fs = require 'fs'
|
||||||
|
|
||||||
|
{exec} = require 'child_process'
|
||||||
|
|
||||||
|
task 'test', 'test snowflake.coffee', () ->
|
||||||
|
exec 'coffee snowflake_test.coffee -v', (err, stdout, stderr) ->
|
||||||
|
throw err if err
|
||||||
|
console.log stdout + stderr
|
11
proxy/README.md
Normal file
11
proxy/README.md
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
This is the browser proxy component of Snowflake.
|
||||||
|
|
||||||
|
### Testing:
|
||||||
|
|
||||||
|
Unit tests are available with:
|
||||||
|
```
|
||||||
|
cake test
|
||||||
|
```
|
||||||
|
|
||||||
|
To run locally, start a webserver and navigate to `snowflake.html`.
|
||||||
|
|
80
proxy/snowflake_test.coffee
Normal file
80
proxy/snowflake_test.coffee
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
s = require './snowflake'
|
||||||
|
|
||||||
|
VERBOSE = false
|
||||||
|
if process.argv.indexOf("-v") >= 0
|
||||||
|
VERBOSE = true
|
||||||
|
numTests = 0
|
||||||
|
numFailed = 0
|
||||||
|
|
||||||
|
announce = (testName) ->
|
||||||
|
if VERBOSE
|
||||||
|
# if (!top)
|
||||||
|
# console.log();
|
||||||
|
console.log testName
|
||||||
|
# top = false
|
||||||
|
|
||||||
|
pass = (test) ->
|
||||||
|
numTests++;
|
||||||
|
if VERBOSE
|
||||||
|
console.log "PASS " + test
|
||||||
|
|
||||||
|
fail = (test, expected, actual) ->
|
||||||
|
numTests++
|
||||||
|
numFailed++
|
||||||
|
console.log "FAIL " + test + " expected: " + expected + " actual: " + actual
|
||||||
|
|
||||||
|
|
||||||
|
testBuildUrl = ->
|
||||||
|
TESTS = [{
|
||||||
|
args: ["http", "example.com"]
|
||||||
|
expected: "http://example.com"
|
||||||
|
},{
|
||||||
|
args: ["http", "example.com", 80]
|
||||||
|
expected: "http://example.com"
|
||||||
|
},{
|
||||||
|
args: ["http", "example.com", 81],
|
||||||
|
expected: "http://example.com:81"
|
||||||
|
},{
|
||||||
|
args: ["https", "example.com", 443]
|
||||||
|
expected: "https://example.com"
|
||||||
|
},{
|
||||||
|
args: ["https", "example.com", 444]
|
||||||
|
expected: "https://example.com:444"
|
||||||
|
},{
|
||||||
|
args: ["http", "example.com", 80, "/"]
|
||||||
|
expected: "http://example.com/"
|
||||||
|
},{
|
||||||
|
args: ["http", "example.com", 80, "/test?k=%#v"]
|
||||||
|
expected: "http://example.com/test%3Fk%3D%25%23v"
|
||||||
|
},{
|
||||||
|
args: ["http", "example.com", 80, "/test", []]
|
||||||
|
expected: "http://example.com/test?"
|
||||||
|
},{
|
||||||
|
args: ["http", "example.com", 80, "/test", [["k", "%#v"]]]
|
||||||
|
expected: "http://example.com/test?k=%25%23v"
|
||||||
|
},{
|
||||||
|
args: ["http", "example.com", 80, "/test", [["a", "b"], ["c", "d"]]]
|
||||||
|
expected: "http://example.com/test?a=b&c=d"
|
||||||
|
},{
|
||||||
|
args: ["http", "1.2.3.4"]
|
||||||
|
expected: "http://1.2.3.4"
|
||||||
|
},{
|
||||||
|
args: ["http", "1:2::3:4"]
|
||||||
|
expected: "http://[1:2::3:4]"
|
||||||
|
},{
|
||||||
|
args: ["http", "bog][us"]
|
||||||
|
expected: "http://bog%5D%5Bus"
|
||||||
|
},{
|
||||||
|
args: ["http", "bog:u]s"]
|
||||||
|
expected: "http://bog%3Au%5Ds"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
announce "-- testBuildUrl --"
|
||||||
|
for test in TESTS
|
||||||
|
actual = s.buildUrl.apply undefined, test.args
|
||||||
|
if actual == test.expected
|
||||||
|
pass test.args
|
||||||
|
else
|
||||||
|
fail test.args, test.expected, actual
|
||||||
|
|
||||||
|
testBuildUrl()
|
Loading…
Add table
Add a link
Reference in a new issue