-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0647b8c
commit 9a92172
Showing
13 changed files
with
241 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ defmodule Assent.Strategy.GoogleTest do | |
} | ||
@user %{ | ||
"email" => "[email protected]", | ||
"email_verified" => "true", | ||
"email_verified" => true, | ||
"hd" => "example.com", | ||
"sub" => "10769150350006150715113082367" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ defmodule Assent.Strategy.VKTest do | |
@user %{ | ||
"given_name" => "Lindsay", | ||
"family_name" => "Stirling", | ||
"sub" => 210_700_286, | ||
"sub" => "210700286", | ||
"email" => "[email protected]" | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,12 +63,101 @@ defmodule Assent.StrategyTest do | |
"http://example.com/path?a=1&b[c]=2&b[d][e]=3&f[]=4&f[]=5" | ||
end | ||
|
||
test "normalize_userinfo/2" do | ||
user = %{"email" => "[email protected]", "name" => nil, "nickname" => "foo"} | ||
extra = %{"a" => "1"} | ||
expected = %{"email" => "[email protected]", "nickname" => "foo", "a" => "1"} | ||
|
||
assert Strategy.normalize_userinfo(user, extra) == {:ok, expected} | ||
describe "normalize_userinfo/2" do | ||
@valid_user %{ | ||
"sub" => "123", | ||
"email" => "[email protected]", | ||
"email_verified" => true, | ||
"address" => %{ | ||
"formatted" => "456" | ||
}, | ||
"updated_at" => 1_516_239_022 | ||
} | ||
|
||
@invalid_user %{ | ||
"sub" => true, | ||
"address" => %{ | ||
"formatted" => true | ||
} | ||
} | ||
|
||
@expected_user %{ | ||
"sub" => "123", | ||
"email" => "[email protected]", | ||
"email_verified" => true, | ||
"address" => %{ | ||
"formatted" => "456" | ||
}, | ||
"updated_at" => 1_516_239_022 | ||
} | ||
|
||
test "with incorrect claim type" do | ||
assert {:error, %Assent.CastClaimsError{} = error} = | ||
Strategy.normalize_userinfo(@invalid_user, %{}) | ||
|
||
assert Exception.message(error) == """ | ||
The following claims couldn't be cast: | ||
- "address" -> "formatted" to :binary | ||
- "sub" to :binary | ||
""" | ||
end | ||
|
||
test "with atom value claim" do | ||
user = %{"sub" => :invalid} | ||
|
||
assert {:error, %Assent.CastClaimsError{} = error} = Strategy.normalize_userinfo(user, %{}) | ||
assert error.invalid_types == %{"sub" => :binary} | ||
end | ||
|
||
test "with binary type claim with integer value" do | ||
user = %{"sub" => 123} | ||
|
||
assert {:ok, %{"sub" => "123"}} = Strategy.normalize_userinfo(user, %{}) | ||
end | ||
|
||
test "with integer type claim with invalid binary value" do | ||
user = %{"updated_at" => "123a1"} | ||
|
||
assert {:error, %Assent.CastClaimsError{} = error} = Strategy.normalize_userinfo(user, %{}) | ||
assert error.invalid_types == %{"updated_at" => :integer} | ||
end | ||
|
||
test "with integer type claim with valid binary value" do | ||
user = %{"updated_at" => "123"} | ||
|
||
assert {:ok, %{"updated_at" => 123}} = Strategy.normalize_userinfo(user, %{}) | ||
end | ||
|
||
test "with boolean type claim with string binary value" do | ||
user = %{"email_verified" => "true"} | ||
|
||
assert {:ok, %{"email_verified" => true}} = Strategy.normalize_userinfo(user, %{}) | ||
|
||
user = %{"email_verified" => "false"} | ||
|
||
assert {:ok, %{"email_verified" => false}} = Strategy.normalize_userinfo(user, %{}) | ||
end | ||
|
||
test "casts" do | ||
assert Strategy.normalize_userinfo(@valid_user) == {:ok, @expected_user} | ||
end | ||
|
||
test "with unknown claims" do | ||
user = | ||
@valid_user | ||
|> Map.put("foo", "bar") | ||
|> Map.put("address", Map.put(@valid_user["address"], "foo", "bar")) | ||
|
||
assert Strategy.normalize_userinfo(user) == {:ok, @expected_user} | ||
end | ||
|
||
test "with extra" do | ||
extra = %{"a" => 1, "sub" => "different-sub"} | ||
expected_user = Map.put(@expected_user, "a", 1) | ||
|
||
assert Strategy.normalize_userinfo(@valid_user, extra) == {:ok, expected_user} | ||
end | ||
end | ||
|
||
test "prune/1" do | ||
|