Skip to content

Commit 26c8ea3

Browse files
yashin5Yashin Santos
authored andcommitted
Merge branch 'master' into feat/add_show_admin_endpoint
2 parents adaa2ea + 368427e commit 26c8ea3

File tree

17 files changed

+134
-73
lines changed

17 files changed

+134
-73
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ jobs:
109109
uses: actions/cache@v2
110110
id: plt-cache
111111
with:
112-
path: _build/plts
112+
path: dializer/
113113
key: ${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-plts-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
114114

115115
- name: Generate PLT
116116
if: steps.plt-cache.outputs.cache-hit != 'true'
117117
run: |
118-
mkdir -p _build/plts
118+
mkdir -p dialyzer/
119119
mix dialyzer --plt
120120
121121
- name: Run dialyzer

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
# The directory Mix downloads your dependencies sources to.
88
/deps/
99

10+
# The directory where the files will be saved on every build.
11+
/dialyzer/
12+
1013
# Where third-party dependencies like ExDoc output generated docs.
1114
/doc/
1215

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,14 @@
22

33
**This is a work in progress and every contribution is welcome :)**
44

5-
**TODO: Add description**
6-
75
## Requirements
86

9-
- Elixir `1.11` using `OTP-23`;
7+
- Elixir `1.11`;
108
- Erlang `23.1`;
119
- Docker-compose (Just when running in dev enviroment);
1210

1311
## Running it locally
1412

15-
First you should install all requirement, we recommend you to use [asdf](https://github.com/asdf-vm/asdf).
16-
17-
If you are using `asdf` just run:
18-
19-
- `asdf plugin-add elixir`;
20-
- `asdf plugin-add erlang`;
21-
- `asdf install`;
22-
2313
In order to prepare the application run:
2414

2515
- `docker-compose up` to get your containers running;
@@ -47,7 +37,7 @@ ResourceManager.Repo.all(ResourceManager.Identities.Schemas.ClientApplication) |
4737

4838
Check out the [rest api guide](https://github.com/lcpojr/watcher_ex/blob/master/apps/rest_api/README.md) on the specific application `README.md`.
4939

50-
## Testing
40+
### Testing
5141

5242
Before you can run the tests you should setup the test dabatase by using `mix test_setup`. After that just call `mix test` or `mix coveralls` if you want to check code coverage.
5343

apps/authenticator/test/authenticator/sign_in/commands/client_credentials_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ defmodule Authenticator.SignIn.Commands.ClientCredentialsTest do
106106
test "succeeds using client_assertions and generates an access_token" do
107107
scopes = RF.insert_list!(:scope, 3)
108108
app = RF.insert!(:client_application, grant_flows: ["client_credentials"])
109-
public_key = RF.insert!(:public_key, client_application: app, value: get_priv_public_key())
109+
public_key = RF.insert!(:public_key, client_application: app, value: get_public_key())
110110

111-
signer = Joken.Signer.create("RS256", %{"pem" => get_priv_private_key()})
111+
signer = Joken.Signer.create("RS256", %{"pem" => get_private_key()})
112112

113113
client_assertion =
114114
ClientAssertion.generate_and_sign!(
@@ -144,9 +144,9 @@ defmodule Authenticator.SignIn.Commands.ClientCredentialsTest do
144144
test "succeeds using client_assertions and generates a refresh_token" do
145145
scopes = RF.insert_list!(:scope, 3)
146146
app = RF.insert!(:client_application, grant_flows: ["client_credentials", "refresh_token"])
147-
public_key = RF.insert!(:public_key, client_application: app, value: get_priv_public_key())
147+
public_key = RF.insert!(:public_key, client_application: app, value: get_public_key())
148148

149-
signer = Joken.Signer.create("RS256", %{"pem" => get_priv_private_key()})
149+
signer = Joken.Signer.create("RS256", %{"pem" => get_private_key()})
150150

151151
client_assertion =
152152
ClientAssertion.generate_and_sign!(

apps/authenticator/test/authenticator/sign_in/commands/resource_owner_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@ defmodule Authenticator.SignIn.Commands.ResourceOwnerTest do
129129
scopes = RF.insert_list!(:scope, 3)
130130
user = RF.insert!(:user)
131131
app = RF.insert!(:client_application)
132-
public_key = RF.insert!(:public_key, client_application: app, value: get_priv_public_key())
132+
public_key = RF.insert!(:public_key, client_application: app, value: get_public_key())
133133
hash = RF.gen_hashed_password("MyPassw@rd234")
134134
password = RF.insert!(:password, user: user, password_hash: hash)
135135

136-
signer = Joken.Signer.create("RS256", %{"pem" => get_priv_private_key()})
136+
signer = Joken.Signer.create("RS256", %{"pem" => get_private_key()})
137137

138138
client_assertion =
139139
ClientAssertion.generate_and_sign!(
@@ -177,11 +177,11 @@ defmodule Authenticator.SignIn.Commands.ResourceOwnerTest do
177177
scopes = RF.insert_list!(:scope, 3)
178178
user = RF.insert!(:user)
179179
app = RF.insert!(:client_application, grant_flows: ["resource_owner", "refresh_token"])
180-
public_key = RF.insert!(:public_key, client_application: app, value: get_priv_public_key())
180+
public_key = RF.insert!(:public_key, client_application: app, value: get_public_key())
181181
hash = RF.gen_hashed_password("MyPassw@rd234")
182182
password = RF.insert!(:password, user: user, password_hash: hash)
183183

184-
signer = Joken.Signer.create("RS256", %{"pem" => get_priv_private_key()})
184+
signer = Joken.Signer.create("RS256", %{"pem" => get_private_key()})
185185

186186
client_assertion =
187187
ClientAssertion.generate_and_sign!(

apps/authenticator/test/support/factory.ex

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ defmodule Authenticator.Factory do
66
alias Authenticator.Sessions.Tokens.{AccessToken, RefreshToken}
77
alias Authenticator.SignIn.Schemas.{ApplicationAttempt, UserAttempt}
88

9-
@doc false
9+
@doc "Builds a default struct from the requested model"
10+
@spec build(model :: atom()) :: struct()
1011
def build(:session) do
1112
jti = Ecto.UUID.generate()
1213

@@ -51,50 +52,60 @@ defmodule Authenticator.Factory do
5152
}
5253
end
5354

54-
@doc false
55+
@doc "Returns the a model struct with the given attributes"
56+
@spec build(factory_name :: atom(), attributes :: Keyword.t()) :: struct()
5557
def build(factory_name, attributes) when is_atom(factory_name) and is_list(attributes) do
5658
factory_name
5759
|> build()
5860
|> struct!(attributes)
5961
end
6062

61-
@doc false
63+
@doc "Inserts a model with the given attributes on database"
64+
@spec insert!(factory_name :: atom(), attributes :: Keyword.t()) :: struct()
6265
def insert!(factory_name, attributes \\ []) when is_atom(factory_name) do
6366
factory_name
6467
|> build(attributes)
6568
|> Repo.insert!()
6669
end
6770

68-
@doc false
71+
@doc "Inserts a list of the given model on database"
72+
@spec insert_list!(
73+
factory_name :: atom(),
74+
count :: integer(),
75+
attributes :: Keyword.t()
76+
) :: list(struct())
6977
def insert_list!(factory_name, count \\ 10, attributes \\ []) when is_atom(factory_name),
7078
do: Enum.map(0..count, fn _ -> insert!(factory_name, attributes) end)
7179

72-
@doc false
73-
def build_access_token(claims), do: AccessToken.generate_and_sign(claims)
80+
@doc "Returns an mocked access token using the given claims"
81+
@spec build_access_token(claims :: map()) :: {:ok, token :: String.t(), claims :: map()}
82+
def build_access_token(claims) when is_map(claims), do: AccessToken.generate_and_sign(claims)
7483

75-
@doc false
76-
def build_refresh_token(claims), do: RefreshToken.generate_and_sign(claims)
84+
@doc "Returns an mocked refresh token using the given claims"
85+
@spec build_refresh_token(claims :: map()) :: {:ok, token :: String.t(), claims :: map()}
86+
def build_refresh_token(claims) when is_map(claims), do: RefreshToken.generate_and_sign(claims)
7787

78-
@doc false
88+
@doc "Returns an default token expiration"
89+
@spec default_expiration() :: NaiveDateTime.t()
7990
def default_expiration do
8091
NaiveDateTime.utc_now()
8192
|> NaiveDateTime.truncate(:second)
8293
|> NaiveDateTime.add(60 * 60 * 24, :second)
8394
end
8495

85-
@doc false
86-
def get_priv_public_key do
87-
:authenticator
88-
|> :code.priv_dir()
89-
|> Path.join("/keys/authenticator_key.pub")
96+
@doc "Returns the mocked public key"
97+
@spec get_public_key() :: String.t()
98+
def get_public_key do
99+
File.cwd!()
100+
|> Path.join("/test/support/mocks/keys/public_key.pub")
90101
|> File.read!()
91102
end
92103

93-
@doc false
94-
def get_priv_private_key do
95-
:authenticator
96-
|> :code.priv_dir()
97-
|> Path.join("/keys/authenticator_key.pem")
104+
@doc "Returns the mocked private key"
105+
@spec get_private_key() :: String.t()
106+
def get_private_key do
107+
File.cwd!()
108+
|> Path.join("/test/support/mocks/keys/private_key.pem")
98109
|> File.read!()
99110
end
100111
end

apps/resource_manager/test/resource_manager/credentials/public_key_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule ResourceManager.Credentials.PublicKeysTest do
1717

1818
params = %{
1919
client_application_id: client_application.id,
20-
value: get_priv_public_key()
20+
value: get_public_key()
2121
}
2222

2323
assert {:ok, %PublicKey{id: id} = public_key} = PublicKeys.create(params)
@@ -32,7 +32,7 @@ defmodule ResourceManager.Credentials.PublicKeysTest do
3232

3333
describe "#{PublicKeys}.update/2" do
3434
test "succeed if params are valid", ctx do
35-
value = get_priv_public_key()
35+
value = get_public_key()
3636

3737
assert {:ok, %PublicKey{id: id, value: ^value} = public_key} =
3838
PublicKeys.update(ctx.public_key, %{value: value})
@@ -47,7 +47,7 @@ defmodule ResourceManager.Credentials.PublicKeysTest do
4747

4848
test "raises if public_key does not exist" do
4949
assert_raise Ecto.NoPrimaryKeyValueError, fn ->
50-
PublicKeys.update(%PublicKey{}, %{value: get_priv_public_key()})
50+
PublicKeys.update(%PublicKey{}, %{value: get_public_key()})
5151
end
5252
end
5353
end

apps/resource_manager/test/resource_manager/identity/commands/create_identity_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ defmodule ResourceManager.Identities.Commands.CreateIdentityTest do
2626
input = %{
2727
name: "my-client-application",
2828
description: "App for tests",
29-
public_key: get_priv_public_key(),
29+
public_key: get_public_key(),
3030
scopes: ctx.scopes
3131
}
3232

0 commit comments

Comments
 (0)