|
1 |
| -using OAuth |
2 |
| -using FactCheck |
3 |
| - |
4 |
| -facts("oauth_timestamp") do |
5 |
| - context("returns a string") do |
6 |
| - @fact typeof(oauth_timestamp()) <: AbstractString --> true |
7 |
| - end |
8 |
| - |
9 |
| - context("returns a value representing a time after 2014-01-25 20:25:00") do |
10 |
| - @fact parse(Int, oauth_timestamp()) > 1422235471 --> true |
11 |
| - end |
12 |
| -end |
13 |
| - |
14 |
| -facts("ouath_nonce") do |
15 |
| - context("returns a string") do |
16 |
| - @fact typeof(oauth_nonce(15)) <: AbstractString --> true |
17 |
| - end |
18 |
| - |
19 |
| - context("with a length equal to the parameter length") do |
20 |
| - @fact length(oauth_nonce(15)) --> 15 |
21 |
| - @fact length(oauth_nonce(20)) --> 20 |
22 |
| - @fact length(oauth_nonce(25)) --> 25 |
23 |
| - @fact length(oauth_nonce(30)) --> 30 |
24 |
| - @fact length(oauth_nonce(32)) --> 32 |
25 |
| - end |
26 |
| -end |
27 |
| - |
28 |
| -facts("oauth_sign_hmac_sha1") do |
29 |
| - context("provides a consistent string") do |
30 |
| - expected = "dR8PcWvTl2FyvVM417iTe/p1XV8=" |
31 |
| - @fact oauth_sign_hmac_sha1("randy", "zwitch") --> expected |
32 |
| - end |
33 |
| -end |
34 |
| - |
35 |
| -facts("oauth_signing_key") do |
36 |
| - context("returns a concatenation of values, seperated by &") do |
37 |
| - result = oauth_signing_key("9djdj82h48djs9d2", "kkk9d7dh3k39sjv7") |
38 |
| - expected = "9djdj82h48djs9d2&kkk9d7dh3k39sjv7" |
39 |
| - @fact result --> expected |
40 |
| - end |
41 |
| -end |
42 |
| - |
43 |
| -facts("oauth_signature_base_string") do |
44 |
| - context("returns a concatinated and percent-encoded string") do |
45 |
| - result = oauth_signature_base_string( |
46 |
| - "POST", "http://example.com", "?julia=fast&lang=elegant" |
47 |
| - ) |
48 |
| - expected = "POST&http%3A%2F%2Fexample.com&%3Fjulia%3Dfast%26lang%3Delegant" |
49 |
| - @fact result --> expected |
50 |
| - end |
51 |
| -end |
52 |
| - |
53 |
| -facts("oauth_percent_encode_keys!") do |
54 |
| - context("replaces un-encoded keys with their encoded versions") do |
55 |
| - params = Dict("badkey!" => "value", "goodkey" => "value") |
56 |
| - expected = Dict("badkey%21" => "value", "goodkey" => "value") |
57 |
| - |
58 |
| - @fact oauth_percent_encode_keys!(params) --> expected |
59 |
| - end |
60 |
| -end |
61 |
| - |
62 |
| -facts("oauth_serialize_url_parameters") do |
63 |
| - context("returns an & concatinated string of key=value") do |
64 |
| - params = Dict("language" => "julia", "result" => "awesome") |
65 |
| - expected = "language=julia&result=awesome" |
66 |
| - @fact oauth_serialize_url_parameters(params) --> expected |
67 |
| - end |
68 |
| -end |
69 |
| - |
70 |
| -facts("encodeURI!") do |
71 |
| - context("escapes all values in the parameters that are strings") do |
72 |
| - params = Dict("iv" => 10, "s" => "value!") |
73 |
| - expected = Dict("iv" => 10, "s" => "value%21") |
74 |
| - |
75 |
| - @fact encodeURI!(params) --> expected |
76 |
| - end |
77 |
| -end |
78 |
| - |
79 |
| -facts("oauth_body_hash_encode") do |
80 |
| - context("returns the base64 encoded SHA1 digest of the data") do |
81 |
| - result = oauth_body_hash_encode("Hello, World!") |
82 |
| - expected = "CgqfKmdylCVXq1NV12r0Qvj2XgE=" |
83 |
| - @fact result --> expected |
84 |
| - end |
85 |
| -end |
86 |
| - |
87 |
| -facts("oauth_body_hash_data") do |
88 |
| - context("returns a string of the oauth_body_hash key-value pair ") do |
89 |
| - result = oauth_body_hash_data("Hello, World!") |
90 |
| - encoded_hash = "CgqfKmdylCVXq1NV12r0Qvj2XgE=" |
91 |
| - expected = "oauth_body_hash=$encoded_hash" |
92 |
| - |
93 |
| - @fact result --> expected |
94 |
| - end |
95 |
| -end |
96 |
| - |
97 |
| -facts("oauth_body_hash_file") do |
98 |
| - context("returns a string of the oauth_body_hash key-value pair ") do |
99 |
| - test_file = joinpath(dirname(@__FILE__), "auth_body_hash_file.txt") |
100 |
| - result = oauth_body_hash_file(test_file) |
101 |
| - encoded_hash = "CgqfKmdylCVXq1NV12r0Qvj2XgE=" |
102 |
| - expected = "oauth_body_hash=$encoded_hash" |
103 |
| - |
104 |
| - @fact result --> expected |
105 |
| - end |
106 |
| -end |
| 1 | +using OAuth, Test |
107 | 2 |
|
108 | 3 |
|
109 |
| -#TODO |
110 |
| -#oauth_header() |
| 4 | +@test typeof(oauth_timestamp()) <: AbstractString |
111 | 5 |
|
| 6 | +@test parse(Int, oauth_timestamp()) > 1422235471 |
112 | 7 |
|
| 8 | +@test typeof(oauth_nonce(15)) <: AbstractString |
113 | 9 |
|
114 |
| -#TODO |
115 |
| -#oauth_request_resource() |
| 10 | +@test length(oauth_nonce(15)) == 15 |
| 11 | +@test length(oauth_nonce(20)) == 20 |
| 12 | +@test length(oauth_nonce(25)) == 25 |
| 13 | +@test length(oauth_nonce(30)) == 30 |
| 14 | +@test length(oauth_nonce(32)) == 32 |
| 15 | + |
| 16 | +@test oauth_sign_hmac_sha1("randy", "zwitch") == "dR8PcWvTl2FyvVM417iTe/p1XV8=" |
| 17 | + |
| 18 | +@test oauth_signing_key("9djdj82h48djs9d2", "kkk9d7dh3k39sjv7") == "9djdj82h48djs9d2&kkk9d7dh3k39sjv7" |
| 19 | + |
| 20 | +@test oauth_signature_base_string("POST", "http://example.com", "?julia=fast&lang=elegant") == |
| 21 | + "POST&http%3A%2F%2Fexample.com&%3Fjulia%3Dfast%26lang%3Delegant" |
| 22 | + |
| 23 | +@test oauth_percent_encode_keys!(Dict("badkey!" => "value", "goodkey" => "value")) == Dict("badkey%21" => "value", "goodkey" => "value") |
| 24 | + |
| 25 | +@test oauth_serialize_url_parameters(Dict("language" => "julia", "result" => "awesome")) == "language=julia&result=awesome" |
116 | 26 |
|
| 27 | +@test encodeURI!(Dict("iv" => 10, "s" => "value!")) == Dict("iv" => 10, "s" => "value%21") |
117 | 28 |
|
118 |
| -FactCheck.exitstatus() |
| 29 | +@test oauth_body_hash_encode("Hello, World!") == "CgqfKmdylCVXq1NV12r0Qvj2XgE=" |
| 30 | + |
| 31 | +@test oauth_body_hash_data("Hello, World!") == "oauth_body_hash=CgqfKmdylCVXq1NV12r0Qvj2XgE=" |
| 32 | + |
| 33 | +test_file = joinpath(dirname(@__FILE__), "auth_body_hash_file.txt") |
| 34 | +@test oauth_body_hash_file(test_file) == "oauth_body_hash=CgqfKmdylCVXq1NV12r0Qvj2XgE=" |
| 35 | + |
| 36 | +#TODO |
| 37 | +#oauth_header() |
| 38 | + |
| 39 | +#TODO |
| 40 | +#oauth_request_resource() |
0 commit comments