-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support oidc and service account bindings in invites (#1171)
- Loading branch information
1 parent
db99828
commit 4dae8ba
Showing
8 changed files
with
87 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ test/ | |
priv/static/ | ||
creds/ | ||
www/ | ||
ai/ | ||
.github/ |
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
10 changes: 10 additions & 0 deletions
10
apps/core/priv/repo/migrations/20230720191356_invite_oidc.exs
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule Core.Repo.Migrations.InviteOidc do | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table(:invites) do | ||
add :oidc_provider_id, references(:oidc_providers, type: :uuid, on_delete: :delete_all) | ||
add :service_account_id, references(:users, type: :uuid, on_delete: :delete_all) | ||
end | ||
end | ||
end |
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 |
---|---|---|
|
@@ -385,6 +385,34 @@ defmodule Core.Services.AccountsTest do | |
assert_receive {:event, %PubSub.UserCreated{item: ^user}} | ||
end | ||
|
||
test "it can bind users to service accounts/oidc providers", %{user: user, account: account} do | ||
oidc = insert(:oidc_provider) | ||
sa = insert(:user, service_account: true, account: account) | ||
group = insert(:group, account: account) | ||
insert(:oidc_provider_binding, provider: oidc, group: group) | ||
policy = insert(:impersonation_policy, user: sa) | ||
insert(:impersonation_policy_binding, policy: policy, group: group) | ||
|
||
{:ok, invite} = Accounts.create_invite(%{ | ||
email: "[email protected]", | ||
oidc_provider_id: oidc.id, | ||
service_account_id: sa.id | ||
}, user) | ||
|
||
{:ok, new_user} = Accounts.realize_invite(%{ | ||
password: "some long password", | ||
name: "Some User" | ||
}, invite.secure_id) | ||
|
||
%{bindings: bindings} = Core.Repo.preload(oidc, [:bindings]) | ||
assert Enum.find_value(bindings, & &1.group_id) == group.id | ||
assert Enum.find_value(bindings, & &1.user_id) == new_user.id | ||
|
||
%{impersonation_policy: %{bindings: bindings}} = Core.Repo.preload(sa, [impersonation_policy: :bindings]) | ||
assert Enum.find_value(bindings, & &1.group_id) == group.id | ||
assert Enum.find_value(bindings, & &1.user_id) == new_user.id | ||
end | ||
|
||
test "it can bind users to groups when realizing an invite", %{user: user, account: account} do | ||
groups = insert_list(2, :group, account: account) | ||
{:ok, invite} = Accounts.create_invite(%{ | ||
|
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