diff --git a/REQUIRE b/REQUIRE index 01b5507..e57d34b 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,3 @@ julia 0.7-alpha -FactCheck MbedTLS HTTP 0.6.1 diff --git a/appveyor.yml b/appveyor.yml index 70be073..3c86871 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,16 +1,18 @@ environment: matrix: - #- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" - #- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" - -## uncomment the following lines to allow failures on nightly julia -## (tests will run but not make your overall status red) -#matrix: -# allow_failures: -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" -# - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" + - julia_version: 0.7 + - julia_version: 1 + - julia_version: nightly + +platform: + - x86 # 32-bit + - x64 # 64-bit + +# # Uncomment the following lines to allow failures on nightly julia +# # (tests will run but not make your overall status red) +# matrix: +# allow_failures: +# - julia_version: latest branches: only: @@ -24,24 +26,18 @@ notifications: on_build_status_changed: false install: - - ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12" -# If there's a newer build queued for the same PR, cancel this one - - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod ` - https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | ` - Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { ` - throw "There are newer queued builds for this pull request, failing early." } -# Download most recent Julia Windows binary - - ps: (new-object net.webclient).DownloadFile( - $env:JULIA_URL, - "C:\projects\julia-binary.exe") -# Run installer silently, output to C:\projects\julia - - C:\projects\julia-binary.exe /S /D=C:\projects\julia + - ps: iex ((new-object net.webclient).DownloadString("https://raw.githubusercontent.com/JuliaCI/Appveyor.jl/version-1/bin/install.ps1")) build_script: -# Need to convert from shallow to complete for Pkg.clone to work - - IF EXIST .git\shallow (git fetch --unshallow) - - C:\projects\julia\bin\julia -e "versioninfo(); - Pkg.clone(pwd(), \"OAuth\"); Pkg.build(\"OAuth\")" + - echo "%JL_BUILD_SCRIPT%" + - C:\julia\bin\julia -e "%JL_BUILD_SCRIPT%" test_script: - - C:\projects\julia\bin\julia -e "Pkg.test(\"OAuth\")" + - echo "%JL_TEST_SCRIPT%" + - C:\julia\bin\julia -e "%JL_TEST_SCRIPT%" + +# # Uncomment to support code coverage upload. Should only be enabled for packages +# # which would have coverage gaps without running on Windows +# on_success: +# - echo "%JL_CODECOV_SCRIPT%" +# - C:\julia\bin\julia -e "%JL_CODECOV_SCRIPT%" diff --git a/src/OAuth.jl b/src/OAuth.jl index 7a2d1e6..21400ba 100644 --- a/src/OAuth.jl +++ b/src/OAuth.jl @@ -2,7 +2,7 @@ __precompile__() module OAuth -using HTTP, MbedTLS +using HTTP, MbedTLS, Base64, Random export oauth_timestamp, diff --git a/test/runtests.jl b/test/runtests.jl index cf58b93..1012b7b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,118 +1,40 @@ -using OAuth -using FactCheck - -facts("oauth_timestamp") do - context("returns a string") do - @fact typeof(oauth_timestamp()) <: AbstractString --> true - end - - context("returns a value representing a time after 2014-01-25 20:25:00") do - @fact parse(Int, oauth_timestamp()) > 1422235471 --> true - end -end - -facts("ouath_nonce") do - context("returns a string") do - @fact typeof(oauth_nonce(15)) <: AbstractString --> true - end - - context("with a length equal to the parameter length") do - @fact length(oauth_nonce(15)) --> 15 - @fact length(oauth_nonce(20)) --> 20 - @fact length(oauth_nonce(25)) --> 25 - @fact length(oauth_nonce(30)) --> 30 - @fact length(oauth_nonce(32)) --> 32 - end -end - -facts("oauth_sign_hmac_sha1") do - context("provides a consistent string") do - expected = "dR8PcWvTl2FyvVM417iTe/p1XV8=" - @fact oauth_sign_hmac_sha1("randy", "zwitch") --> expected - end -end - -facts("oauth_signing_key") do - context("returns a concatenation of values, seperated by &") do - result = oauth_signing_key("9djdj82h48djs9d2", "kkk9d7dh3k39sjv7") - expected = "9djdj82h48djs9d2&kkk9d7dh3k39sjv7" - @fact result --> expected - end -end - -facts("oauth_signature_base_string") do - context("returns a concatinated and percent-encoded string") do - result = oauth_signature_base_string( - "POST", "http://example.com", "?julia=fast&lang=elegant" - ) - expected = "POST&http%3A%2F%2Fexample.com&%3Fjulia%3Dfast%26lang%3Delegant" - @fact result --> expected - end -end - -facts("oauth_percent_encode_keys!") do - context("replaces un-encoded keys with their encoded versions") do - params = Dict("badkey!" => "value", "goodkey" => "value") - expected = Dict("badkey%21" => "value", "goodkey" => "value") - - @fact oauth_percent_encode_keys!(params) --> expected - end -end - -facts("oauth_serialize_url_parameters") do - context("returns an & concatinated string of key=value") do - params = Dict("language" => "julia", "result" => "awesome") - expected = "language=julia&result=awesome" - @fact oauth_serialize_url_parameters(params) --> expected - end -end - -facts("encodeURI!") do - context("escapes all values in the parameters that are strings") do - params = Dict("iv" => 10, "s" => "value!") - expected = Dict("iv" => 10, "s" => "value%21") - - @fact encodeURI!(params) --> expected - end -end - -facts("oauth_body_hash_encode") do - context("returns the base64 encoded SHA1 digest of the data") do - result = oauth_body_hash_encode("Hello, World!") - expected = "CgqfKmdylCVXq1NV12r0Qvj2XgE=" - @fact result --> expected - end -end - -facts("oauth_body_hash_data") do - context("returns a string of the oauth_body_hash key-value pair ") do - result = oauth_body_hash_data("Hello, World!") - encoded_hash = "CgqfKmdylCVXq1NV12r0Qvj2XgE=" - expected = "oauth_body_hash=$encoded_hash" - - @fact result --> expected - end -end - -facts("oauth_body_hash_file") do - context("returns a string of the oauth_body_hash key-value pair ") do - test_file = joinpath(dirname(@__FILE__), "auth_body_hash_file.txt") - result = oauth_body_hash_file(test_file) - encoded_hash = "CgqfKmdylCVXq1NV12r0Qvj2XgE=" - expected = "oauth_body_hash=$encoded_hash" - - @fact result --> expected - end -end +using OAuth, Test -#TODO -#oauth_header() +@test typeof(oauth_timestamp()) <: AbstractString +@test parse(Int, oauth_timestamp()) > 1422235471 +@test typeof(oauth_nonce(15)) <: AbstractString -#TODO -#oauth_request_resource() +@test length(oauth_nonce(15)) == 15 +@test length(oauth_nonce(20)) == 20 +@test length(oauth_nonce(25)) == 25 +@test length(oauth_nonce(30)) == 30 +@test length(oauth_nonce(32)) == 32 + +@test oauth_sign_hmac_sha1("randy", "zwitch") == "dR8PcWvTl2FyvVM417iTe/p1XV8=" + +@test oauth_signing_key("9djdj82h48djs9d2", "kkk9d7dh3k39sjv7") == "9djdj82h48djs9d2&kkk9d7dh3k39sjv7" + +@test oauth_signature_base_string("POST", "http://example.com", "?julia=fast&lang=elegant") == + "POST&http%3A%2F%2Fexample.com&%3Fjulia%3Dfast%26lang%3Delegant" + +@test oauth_percent_encode_keys!(Dict("badkey!" => "value", "goodkey" => "value")) == Dict("badkey%21" => "value", "goodkey" => "value") + +@test oauth_serialize_url_parameters(Dict("language" => "julia", "result" => "awesome")) == "language=julia&result=awesome" +@test encodeURI!(Dict("iv" => 10, "s" => "value!")) == Dict("iv" => 10, "s" => "value%21") -FactCheck.exitstatus() +@test oauth_body_hash_encode("Hello, World!") == "CgqfKmdylCVXq1NV12r0Qvj2XgE=" + +@test oauth_body_hash_data("Hello, World!") == "oauth_body_hash=CgqfKmdylCVXq1NV12r0Qvj2XgE=" + +test_file = joinpath(dirname(@__FILE__), "auth_body_hash_file.txt") +@test oauth_body_hash_file(test_file) == "oauth_body_hash=CgqfKmdylCVXq1NV12r0Qvj2XgE=" + +#TODO +#oauth_header() + +#TODO +#oauth_request_resource()