-
-
Notifications
You must be signed in to change notification settings - Fork 71
Basic Setup scripts #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
514e21f
121637a
bacbffb
43056ec
de0e73c
2201d57
761b52a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ erl_crash.dump | |
/tmp | ||
.DS_Store | ||
/.elixir_ls | ||
.tool-versions | ||
/priv/pg_data |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
# install deps | ||
|
||
mix deps.get | ||
mix deps.compile | ||
|
||
|
||
|
||
# setup postgresql | ||
|
||
Running postgresql via Docker can make setting up tests simple. | ||
|
||
However because postgresql is run inside the docker host, any connections to it invoke | ||
the access control file "pg_hba.conf" | ||
|
||
A simple way to set docker postgresql up for tests is to use the below script | ||
and then stop the script, modifiy the pg_hba.conf and then restart the script. | ||
|
||
This is fine for development but no production machine should trust any user incoming. | ||
|
||
1) start postgres via script (will download and run image) | ||
``` | ||
dev/postgres.zsh | ||
``` | ||
2) stop the script (CTRL-C) | ||
3) change last line of priv/pg_data/pg_hba.conf to "host all all all trust" | ||
4) restart postgres via script | ||
``` | ||
dev/postgres.zsh | ||
``` | ||
|
||
# running tests | ||
|
||
|
||
``` | ||
mix clean && mix test | ||
``` | ||
|
||
|
||
UUID test needs clean compilation. | ||
``` | ||
mix clean && UUID=1 mix tes | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env zsh | ||
SCRIPT_DIR=$0:a:h | ||
DATA_DIR=$SCRIPT_DIR/../priv/pg_data | ||
PG_NAME=postgres-oauth2-provider | ||
mkdir -p $DATA_DIR | ||
docker stop $PG_NAME | ||
docker run --rm --name $PG_NAME -e POSTGRES_USER=$USER -e POSTGRES_PASSWORD=secret -p 5432:5432 -v $DATA_DIR:/var/lib/postgresql/data postgres | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ defmodule ExOauth2Provider.Authorization.CodeTest do | |
alias Dummy.{OauthAccessGrants.OauthAccessGrant, Repo} | ||
|
||
@client_id "Jf5rM8hQBc" | ||
@valid_request %{"client_id" => @client_id, "response_type" => "code", "scope" => "app:read app:write"} | ||
@valid_request %{"client_id" => @client_id, "response_type" => "code"} | ||
@invalid_request %{error: :invalid_request, | ||
error_description: "The request is missing a required parameter, includes an unsupported parameter value, or is otherwise malformed." | ||
} | ||
|
@@ -83,6 +83,12 @@ defmodule ExOauth2Provider.Authorization.CodeTest do | |
%{resource_owner: resource_owner, application: application} | ||
end | ||
|
||
test "with no scope", %{resource_owner: resource_owner, application: application} do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is tested with an application that doesn't have any scope, but relies on the server scope. Is this as intended? It may make more sense to put it outside this describe block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes hmm - I think that is fair. I really appreciate your thoughts Maybe the right question we need to be asking is : Is a token with no scope legitimate if the application specifies a scope? |
||
request = Map.delete(@valid_request, "scope") | ||
|
||
assert Authorization.preauthorize(resource_owner, request, otp_app: :ex_oauth2_provider) == {:ok, application, []} | ||
end | ||
|
||
test "with limited server scope", %{resource_owner: resource_owner, application: application} do | ||
request = Map.merge(@valid_request, %{"scope" => "read"}) | ||
|
||
|
@@ -134,12 +140,20 @@ defmodule ExOauth2Provider.Authorization.CodeTest do | |
%{resource_owner: resource_owner, application: application} | ||
end | ||
|
||
test "generates grant with no scope passed", %{resource_owner: resource_owner} do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, this is a specific test environment, and it may make more sense to put it outside this describe block unless you need to test this in a no scope application environment (remember, the server scopes are still there). |
||
request = Map.delete(@valid_request, "scope") | ||
assert {:native_redirect, %{code: code}} = Authorization.authorize(resource_owner, request, otp_app: :ex_oauth2_provider) | ||
|
||
access_grant = Repo.get_by(OauthAccessGrant, token: code) | ||
assert access_grant.resource_owner_id == resource_owner.id | ||
end | ||
|
||
test "error when invalid server scope", %{resource_owner: resource_owner} do | ||
request = Map.merge(@valid_request, %{"scope" => "public profile"}) | ||
assert Authorization.authorize(resource_owner, request, otp_app: :ex_oauth2_provider) == {:error, @invalid_scope, :unprocessable_entity} | ||
end | ||
|
||
test "generates grant", %{resource_owner: resource_owner} do | ||
test "generates grant with public scope", %{resource_owner: resource_owner} do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't call this public scope, since the scope's actual name has no meaning in these tests. I just ensures that the server scope works. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah - I though the intent was that it was a non-sensical scope. |
||
request = Map.merge(@valid_request, %{"scope" => "public"}) | ||
assert {:native_redirect, %{code: code}} = Authorization.authorize(resource_owner, request, otp_app: :ex_oauth2_provider) | ||
|
||
|
@@ -160,7 +174,7 @@ defmodule ExOauth2Provider.Authorization.CodeTest do | |
|
||
assert access_grant.resource_owner_id == resource_owner.id | ||
assert access_grant.expires_in == Config.authorization_code_expires_in(otp_app: :ex_oauth2_provider) | ||
assert access_grant.scopes == @valid_request["scope"] | ||
assert access_grant.scopes == "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be tested with scope. |
||
end | ||
|
||
test "#authorize/3 generates grant with redirect uri", %{resource_owner: resource_owner, application: application} do | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep this as it is, and instead just do
Map.delete(@valid_request, "scope")
in the "with no scope" test? The default setup for most OAuth2 apps is to have scopes, so that's why it's a default in these tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danschultzer : since scopes are an optional part of OAUTH i wanted to have some tests that did sanity check and make sure it would function.
I see no problem with keeping it. I could rename it to @valid_request_with_scope and make one for no scope.