Skip to content

Commit

Permalink
Merge da9f98b into d4cbb77
Browse files Browse the repository at this point in the history
  • Loading branch information
achedeuzot committed Jun 18, 2020
2 parents d4cbb77 + da9f98b commit 3fb7915
Show file tree
Hide file tree
Showing 13 changed files with 406 additions and 15 deletions.
12 changes: 6 additions & 6 deletions .travis.yml
Expand Up @@ -38,12 +38,12 @@ matrix:
otp_release: '21.3'
- elixir: '1.9'
otp_release: '22.0'
# - elixir: '1.10'
# otp_release: '20.3'
# - elixir: '1.10'
# otp_release: '21.3'
# - elixir: '1.10'
# otp_release: '22.0'
- elixir: '1.10'
otp_release: '20.3'
- elixir: '1.10'
otp_release: '21.3'
- elixir: '1.10'
otp_release: '22.0'

env:
global:
Expand Down
1 change: 1 addition & 0 deletions config/config.exs
Expand Up @@ -28,3 +28,4 @@ use Mix.Config
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"
if Mix.env() == :test, do: import_config("test.exs")
17 changes: 17 additions & 0 deletions config/test.exs
@@ -0,0 +1,17 @@
use Mix.Config

config :ueberauth, Ueberauth,
json_library: Jason,
providers: [
auth0: {Ueberauth.Strategy.Auth0, []}
]

config :ueberauth, Ueberauth.Strategy.Auth0.OAuth,
domain: "example-app.auth0.com",
client_id: "clientidsomethingrandom",
client_secret: "clientsecret-somethingsecret"

config :exvcr,
vcr_cassette_library_dir: "test/fixtures/vcr_cassettes"

config :plug, :validate_header_keys_during_test, true
6 changes: 5 additions & 1 deletion mix.exs
Expand Up @@ -24,7 +24,11 @@ defmodule UeberauthAuth0.Mixfile do
coveralls: :test,
"coveralls.detail": :test,
"coveralls.post": :test,
"coveralls.html": :test
"coveralls.html": :test,
vcr: :test,
"vcr.delete": :test,
"vcr.check": :test,
"vcr.show": :test
],

# Type checking
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/auth0.json
@@ -0,0 +1,9 @@
{
"email": "testuser@example.com",
"email_verified": false,
"name": "testuser@example.com",
"nickname": "testuser",
"picture": "https://s.gravatar.com/avatar/7ec7606c46a14a7ef514d1f1f9038823?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Ftu.png",
"sub": "auth0|lyy5vutbn9qfmihil7pvpo66",
"updated_at": "2020-02-19T12:34:56.784Z"
}
1 change: 1 addition & 0 deletions test/fixtures/auth0_response.html
@@ -0,0 +1 @@
<html><body>You are being <a href="https://example-app.auth0.com/authorize?client_id=clientidsomethingrandom&amp;redirect_uri=http%3A%2F%2Fwww.example.com%2Fauth%2Fauth0%2Fcallback&amp;response_type=code&amp;scope=openid+profile+email">redirected</a>.</body></html>
40 changes: 40 additions & 0 deletions test/fixtures/vcr_cassettes/auth0-invalid-code.json
@@ -0,0 +1,40 @@
[
{
"request": {
"body": "client_id=clientidKFpqmR7aO1iVUOQR1LMKbZvk&client_secret=clientsecrethzqAhvWpJhAehfkzupWelgut-hRh7ZYOBOmaXsCRryhy7bqWzOCx&code=invalid_code&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fwww.example.com%2Fauth%2Fauth0%2Fcallback",
"headers": {
"content-type": "application/x-www-form-urlencoded",
"accept": "application/json",
"authorization": "Basic Y2xpZW50aWRLRnBxbVI3YU8xaVZVT1FSMUxNS2Jadms6Y2xpZW50c2VjcmV0aHpxQWh2V3BKaEFlaGZrenVwV2VsZ3V0LWhSaDdaWU9CT21hWHNDUnJ5aHk3YnFXek9DeA=="
},
"method": "post",
"options": [],
"request_body": "",
"url": "https://example-app.auth0.com/oauth/token"
},
"response": {
"binary": false,
"body": "{\"error\":\"invalid_grant\",\"error_description\":\"Invalid authorization code\"}",
"headers": {
"Date": "Thu, 18 Jun 2020 07:03:26 GMT",
"Content-Type": "application/json",
"Content-Length": "74",
"Connection": "keep-alive",
"Server": "nginx",
"Vary": "Accept-Encoding",
"ot-tracer-spanid": "5f4018ed528710ca",
"ot-tracer-traceid": "1e9ed8bd1011f221",
"ot-tracer-sampled": "true",
"ot-baggage-auth0-request-id": "b105f9bcbad6f804b763ee88",
"X-Auth0-RequestId": "aedc633e5adea3be8f49",
"Set-Cookie": "did=s%3Av0%3Ace5ff350-b131-11ea-be83-892b118656b2.%2B9lyU8P6x2BabrexQ7tK2sK19C2RkOlnda890p8d9Z0; Max-Age=31557600; Path=/; Expires=Fri, 18 Jun 2021 13:03:26 GMT; HttpOnly; Secure; SameSite=None",
"X-RateLimit-Limit": "30",
"X-RateLimit-Remaining": "29",
"X-RateLimit-Reset": "1592463807",
"cache-control": "private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0, no-transform"
},
"status_code": 403,
"type": "ok"
}
}
]
39 changes: 39 additions & 0 deletions test/fixtures/vcr_cassettes/auth0-no-access-token.json
@@ -0,0 +1,39 @@
[
{
"request": {
"body": "client_id=clientidKFpqmR7aO1iVUOQR1LMKbZvk&client_secret=clientsecrethzqAhvWpJhAehfkzupWelgut-hRh7ZYOBOmaXsCRryhy7bqWzOCx&code=code_abc&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fwww.example.com%2Fauth%2Fauth0%2Fcallback",
"headers": {
"content-type": "application/x-www-form-urlencoded",
"accept": "application/json",
"authorization": "Basic Y2xpZW50aWRLRnBxbVI3YU8xaVZVT1FSMUxNS2Jadms6Y2xpZW50c2VjcmV0aHpxQWh2V3BKaEFlaGZrenVwV2VsZ3V0LWhSaDdaWU9CT21hWHNDUnJ5aHk3YnFXek9DeA=="
},
"method": "post",
"options": [],
"request_body": "",
"url": "https://example-app.auth0.com/oauth/token"
},
"response": {
"binary": false,
"body": "{\"error\":\"something_wrong\",\"error_description\":\"Something went wrong\"}",
"headers": {
"Date": "Wed, 17 Jun 2020 23:39:36 GMT",
"Content-Type": "application/json",
"Content-Length": "69",
"Connection": "keep-alive",
"Server": "nginx",
"ot-tracer-spanid": "3085123a49690f22",
"ot-tracer-traceid": "2611213f15e78af3",
"ot-tracer-sampled": "true",
"ot-baggage-auth0-request-id": "d8916634ed436afe36744f6e",
"X-Auth0-RequestId": "1dd455670d641d81c4c8",
"Set-Cookie": "did=s%3Av0%3Acd966af0-b0e3-11ea-85ed-0d9365a06bc5.25colYvrl8qxIpnLc4gibEDFW5BvUQ6ryaj0zR1P7zc; Max-Age=31557600; Path=/; Expires=Fri, 18 Jun 2021 05:39:36 GMT; HttpOnly; Secure; SameSite=None",
"X-RateLimit-Limit": "30",
"X-RateLimit-Remaining": "29",
"X-RateLimit-Reset": "1592437177",
"cache-control": "private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0, no-transform"
},
"status_code": 200,
"type": "ok"
}
}
]
57 changes: 57 additions & 0 deletions test/fixtures/vcr_cassettes/auth0-responses.json
@@ -0,0 +1,57 @@
[
{
"request": {
"body": "client_id=clientidKFpqmR7aO1iVUOQR1LMKbZvk&client_secret=clientsecrethzqAhvWpJhAehfkzupWelgut-hRh7ZYOBOmaXsCRryhy7bqWzOCx&code=code_abc&grant_type=authorization_code&redirect_uri=http%3A%2F%2Fwww.example.com%2Fauth%2Fauth0%2Fcallback",
"headers": {
"content-type": "application/x-www-form-urlencoded",
"accept": "application/json",
"authorization": "Basic Y2xpZW50aWRLRnBxbVI3YU8xaVZVT1FSMUxNS2Jadms6Y2xpZW50c2VjcmV0aHpxQWh2V3BKaEFlaGZrenVwV2VsZ3V0LWhSaDdaWU9CT21hWHNDUnJ5aHk3YnFXek9DeA=="
},
"method": "post",
"options": [],
"request_body": "",
"url": "https://example-app.auth0.com/oauth/token"
},
"response": {
"binary": false,
"body": "{\"access_token\":\"eyJz93alolk4laUWw\",\"refresh_token\":\"GEbRxBNkitedjnXbL\",\"id_token\":\"eyJ0XAipop4faeEoQ\",\"token_type\":\"Bearer\",\"expires_in\":86400}",
"headers": {
"Date": "Wed, 17 Jun 2020 23:39:36 GMT",
"Content-Type": "application/json",
"Content-Length": "144",
"Connection": "keep-alive",
"X-Auth0-RequestId": "1dd41235665d641d81c4c8",
},
"status_code": 200,
"type": "ok"
}
},
{
"request": {
"body": "",
"headers": {
"accept": "application/json",
"authorization": "Bearer eyJz93alolk4laUWw"
},
"method": "get",
"options": [],
"request_body": "",
"url": "https://example-app.auth0.com/userinfo"
},
"response": {
"binary": false,
"body": "{\"email\":\"testuser@example.com\",\"email_verified\":false,\"name\":\"testuser@example.com\",\"nickname\":\"testuser\",\"picture\":\"https://s.gravatar.com/avatar/7ec7606c46a14a7ef514d1f1f9038823?s=480&r=pg&d=https%3A%2F%2Fcdn.auth0.com%2Favatars%2Ftu.png\",\"sub\":\"auth0|lyy5vutbn9qfmihil7pvpo66\",\"updated_at\":\"2020-02-19T12:34:56.784Z\"}",
"headers": {
"Date": "Wed, 17 Jun 2020 23:39:36 GMT",
"Content-Type": "application/json",
"Content-Length": "144",
"Connection": "keep-alive",
"Server": "nginx",
"X-Auth0-RequestId": "1dd968479496d641d81c4c8",
"cache-control": "private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0, no-transform"
},
"status_code": 200,
"type": "ok"
}
}
]
21 changes: 21 additions & 0 deletions test/strategy/auth0/oauth_test.exs
@@ -0,0 +1,21 @@
defmodule Ueberauth.Strategy.Auth0.OAuthTest do
use ExUnit.Case

import Ueberauth.Strategy.Auth0.OAuth, only: [client: 0]

@test_domain "example-app.auth0.com"

setup do
{:ok, %{client: client()}}
end

test "creates correct client", %{client: client} do
assert client.client_id == "clientidsomethingrandom"
assert client.client_secret == "clientsecret-somethingsecret"
assert client.redirect_uri == ""
assert client.strategy == Ueberauth.Strategy.Auth0.OAuth
assert client.authorize_url == "https://#{@test_domain}/authorize"
assert client.token_url == "https://#{@test_domain}/oauth/token"
assert client.site == "https://#{@test_domain}"
end
end

0 comments on commit 3fb7915

Please sign in to comment.