Skip to content

Commit

Permalink
Merge pull request #40 from DefactoSoftware/marcel/query-param
Browse files Browse the repository at this point in the history
allow matching on a list from 2 to more for key value
  • Loading branch information
tarzan authored Apr 30, 2019
2 parents 6727a4f + c12bf1f commit c43a78d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
15 changes: 11 additions & 4 deletions lib/lti.ex
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,20 @@ defmodule LTI do
defp to_query_params(query) do
query
|> String.split("&")
|> Enum.map(fn pair ->
[key, value] = String.split(pair, "=")
{String.to_atom(key), value}
end)
|> Enum.map(&to_pairs/1)
|> Keyword.new()
end

defp to_pairs(pair) do
pair
|> String.split("=")
|> get_pairs
end

defp get_pairs([key | values]) do
{String.to_atom(key), Enum.join(values, "=")}
end

defp timestamp do
{megasec, sec, _mcs} = :os.timestamp()
"#{megasec * 1_000_000 + sec}"
Expand Down
15 changes: 14 additions & 1 deletion test/lti_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ defmodule LTITest do
use ExUnit.Case
doctest LTI

alias LTI.{Credentials, LaunchParams, OAuthData}
alias LTI.{Credentials, OAuthData}

@credentials %Credentials{url: "https://example.com", secret: "secret", key: "key"}
@credentials_with_query_string %Credentials{
url: "https://example.com?course=course1&subcourse=subcourse1",
secret: "secret",
key: "key"
}
@credentials_with_nested_query_string %Credentials{
url: "https://example.com?course=course1&redirect_uri=https://example.com/index.html?page=5",
secret: "secret",
key: "key"
}
@credentials_with_capitalized_url %Credentials{
url: "https://ExamPle.com",
secret: "secret",
Expand Down Expand Up @@ -69,6 +74,14 @@ defmodule LTITest do
"68JVqL7aRC1meflszD8p+onIvWI="
end

test "signature/3 with url with query string with nested query parameters" do
assert LTI.signature(
@credentials_with_nested_query_string,
@oauth_credentials,
@valid_launch_params
) == "f/DC8AEzcDcMUPs07nc0tPG8/CM="
end

test "oauth_params/1 should always be different" do
refute LTI.oauth_params(@credentials) == LTI.oauth_params(@credentials)
end
Expand Down

0 comments on commit c43a78d

Please sign in to comment.