Skip to content

Commit

Permalink
Fix CT tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maennchen committed Jun 12, 2024
1 parent b2eaafb commit 89cd925
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/part_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ jobs:
matrix:
include:
- elixir: "1.14.5"
otp: "26.2.5"
unstable: false
- elixir: "1.15.8"
otp: "26.2.5"
Expand Down
6 changes: 3 additions & 3 deletions lib/oidcc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ defmodule Oidcc do
...> Oidcc.jwt_profile_token(
...> subject,
...> pid,
...> "client_id",
...> System.fetch_env!("CLIENT_ID"),
...> "client_secret",
...> jwk,
...> %{scope: ["urn:zitadel:iam:org:project:id:zitadel:aud"], kid: kid}
...> %{scope: ["openid", "urn:zitadel:iam:org:project:id:zitadel:aud"], kid: kid}
...> )
"""
Expand Down Expand Up @@ -331,7 +331,7 @@ defmodule Oidcc do
...> pid,
...> System.fetch_env!("CLIENT_CREDENTIALS_CLIENT_ID"),
...> System.fetch_env!("CLIENT_CREDENTIALS_CLIENT_SECRET"),
...> %{scope: ["scope"]}
...> %{scope: ["openid"]}
...> )
"""
Expand Down
6 changes: 3 additions & 3 deletions lib/oidcc/token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ defmodule Oidcc.Token do
...> {:ok, client_context} =
...> Oidcc.ClientContext.from_configuration_worker(
...> pid,
...> "client_id",
...> System.fetch_env!("CLIENT_ID"),
...> "client_secret"
...> )
...>
Expand All @@ -382,7 +382,7 @@ defmodule Oidcc.Token do
...> subject,
...> client_context,
...> jwk,
...> %{scope: ["urn:zitadel:iam:org:project:id:zitadel:aud"], kid: kid}
...> %{scope: ["openid", "urn:zitadel:iam:org:project:id:zitadel:aud"], kid: kid}
...> )
"""
Expand Down Expand Up @@ -427,7 +427,7 @@ defmodule Oidcc.Token do
...> {:ok, %Oidcc.Token{}} =
...> Oidcc.Token.client_credentials(
...> client_context,
...> %{scope: ["scope"]}
...> %{scope: ["openid"]}
...> )
"""
Expand Down
3 changes: 2 additions & 1 deletion priv/test/fixtures/zitadel-client-credentials.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"clientId": "Client Credential Test",
"clientSecret": "wb3poHlNp6fEvcspSnAwnfnkUET0LxbafbsL3kftJuVybcJkHRomGNNgcX3Hl3yf"
"clientSecret": "wb3poHlNp6fEvcspSnAwnfnkUET0LxbafbsL3kftJuVybcJkHRomGNNgcX3Hl3yf",
"project": "231391584430604723"
}
11 changes: 7 additions & 4 deletions test/oidcc/token_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ defmodule Oidcc.TokenTest do

%{
"clientId" => client_credentials_client_id,
"clientSecret" => client_credentials_client_secret
"clientSecret" => client_credentials_client_secret,
"project" => project
} =
:oidcc
|> Application.app_dir("priv/test/fixtures/zitadel-client-credentials.json")
Expand All @@ -30,6 +31,7 @@ defmodule Oidcc.TokenTest do

@client_credentials_client_id client_credentials_client_id
@client_credentials_client_secret client_credentials_client_secret
@project project

@jwt_profile :oidcc
|> Application.app_dir("priv/test/fixtures/zitadel-jwt-profile.json")
Expand All @@ -39,6 +41,7 @@ defmodule Oidcc.TokenTest do

setup_all do
# Used in doctests
System.put_env("CLIENT_ID", @project)
System.put_env("CLIENT_CREDENTIALS_CLIENT_ID", @client_credentials_client_id)
System.put_env("CLIENT_CREDENTIALS_CLIENT_SECRET", @client_credentials_client_secret)
System.put_env("JWT_PROFILE", @jwt_profile)
Expand Down Expand Up @@ -185,7 +188,7 @@ defmodule Oidcc.TokenTest do
{:ok, client_context} =
ClientContext.from_configuration_worker(
pid,
"client_id",
@project,
"client_secret"
)

Expand All @@ -198,7 +201,7 @@ defmodule Oidcc.TokenTest do
subject,
client_context,
jwk,
%{scope: ["urn:zitadel:iam:org:project:id:zitadel:aud"], kid: kid}
%{scope: ["openid", "urn:zitadel:iam:org:project:id:zitadel:aud"], kid: kid}
)
end
end
Expand All @@ -220,7 +223,7 @@ defmodule Oidcc.TokenTest do
assert {:ok, %Token{}} =
Oidcc.Token.client_credentials(
client_context,
%{scope: ["scope"]}
%{scope: ["openid"]}
)
end
end
Expand Down
4 changes: 2 additions & 2 deletions test/oidcc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@ retrieve_jwt_profile_token(_Config) ->
oidcc:jwt_profile_token(
<<"231391584430604723">>,
ZitadelConfigurationPid,
<<"client_id">>,
<<"231391584430604723">>,
<<"client_secret">>,
Key,
#{
scope => [<<"urn:zitadel:iam:org:project:id:zitadel:aud">>],
scope => [<<"openid">>, <<"urn:zitadel:iam:org:project:id:zitadel:aud">>],
kid => maps:get(<<"keyId">>, KeyMap)
}
)
Expand Down
5 changes: 3 additions & 2 deletions test/oidcc_http_util_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

all() ->
[
bad_ssl,
client_cert
bad_ssl
%% Disable because of 403
% client_cert
].

init_per_suite(_Config) ->
Expand Down
11 changes: 7 additions & 4 deletions test/oidcc_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ defmodule OidccTest do

%{
"clientId" => client_credentials_client_id,
"clientSecret" => client_credentials_client_secret
"clientSecret" => client_credentials_client_secret,
"project" => project
} =
:oidcc
|> Application.app_dir("priv/test/fixtures/zitadel-client-credentials.json")
Expand All @@ -17,6 +18,7 @@ defmodule OidccTest do

@client_credentials_client_id client_credentials_client_id
@client_credentials_client_secret client_credentials_client_secret
@project project

@jwt_profile :oidcc
|> Application.app_dir("priv/test/fixtures/zitadel-jwt-profile.json")
Expand All @@ -26,6 +28,7 @@ defmodule OidccTest do

setup_all do
# Used in doctests
System.put_env("CLIENT_ID", @project)
System.put_env("CLIENT_CREDENTIALS_CLIENT_ID", @client_credentials_client_id)
System.put_env("CLIENT_CREDENTIALS_CLIENT_SECRET", @client_credentials_client_secret)
System.put_env("JWT_PROFILE", @jwt_profile)
Expand Down Expand Up @@ -159,10 +162,10 @@ defmodule OidccTest do
Oidcc.jwt_profile_token(
subject,
pid,
"client_id",
@project,
"client_secret",
jwk,
%{scope: ["urn:zitadel:iam:org:project:id:zitadel:aud"], kid: kid}
%{scope: ["openid", "urn:zitadel:iam:org:project:id:zitadel:aud"], kid: kid}
)
end
end
Expand All @@ -179,7 +182,7 @@ defmodule OidccTest do
pid,
@client_credentials_client_id,
@client_credentials_client_secret,
%{scope: ["scope"]}
%{scope: ["openid"]}
)
end
end
Expand Down
6 changes: 3 additions & 3 deletions test/oidcc_token_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ retrieves_jwt_profile_token(_Config) ->

{ok, SalesforceClientContext} = oidcc_client_context:from_configuration_worker(
SalesforceConfigurationPid,
<<"client_id">>,
<<"231391584430604723">>,
<<"client_secret">>
),

{ok, ZitadelClientContext} = oidcc_client_context:from_configuration_worker(
ZitadelConfigurationPid,
<<"client_id">>,
<<"231391584430604723">>,
<<"client_secret">>
),

Expand All @@ -53,7 +53,7 @@ retrieves_jwt_profile_token(_Config) ->
?assertMatch(
{ok, #oidcc_token{}},
oidcc_token:jwt_profile(<<"231391584430604723">>, ZitadelClientContext, Key, #{
scope => [<<"urn:zitadel:iam:org:project:id:zitadel:aud">>],
scope => [<<"openid">>, <<"urn:zitadel:iam:org:project:id:zitadel:aud">>],
kid => maps:get(<<"keyId">>, KeyMap)
})
),
Expand Down

0 comments on commit 89cd925

Please sign in to comment.