Skip to content

Commit 27b1f7f

Browse files
fix(guard): update allowed id providers (#405)
## πŸ“ Description In order to support saml login links without making changes to the database, this is required renderedtext/tasks#8141 ## βœ… Checklist - [x] I have tested this change - [ ] This change requires documentation update
1 parent 3d03712 commit 27b1f7f

File tree

7 files changed

+77
-4
lines changed

7 files changed

+77
-4
lines changed

β€Ž.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*/out/*
22
*/*/out/*
33
**/_wildcard*
4+
**/.tool-versions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class SetDefaultAllowedIdProvidersForOrganizations < ActiveRecord::Migration[5.1]
2+
def up
3+
# Set existing null values to the default
4+
execute("UPDATE organizations SET allowed_id_providers = 'api_token,oidc' WHERE allowed_id_providers IS NULL OR allowed_id_providers = ''")
5+
change_column_default :organizations, :allowed_id_providers, "api_token,oidc"
6+
end
7+
8+
def down
9+
change_column_default :organizations, :allowed_id_providers, nil
10+
end
11+
end

β€Žguard/.tool-versions

Lines changed: 0 additions & 2 deletions
This file was deleted.

β€Žguard/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: '3.6'
33
services:
44
app:
55
container_name: guard
6-
image: ${IMAGE:-guard}:${TAG:-latest}
6+
image: ${IMAGE:-guard}:${TAG:-test}
77
build:
88
context: ..
99
cache_from:

β€Žguard/lib/guard/grpc_servers/organization_server.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,19 @@ defmodule Guard.GrpcServers.OrganizationServer do
485485
ip_allow_list: Enum.join(proto_org.ip_allow_list, ",")
486486
}
487487

488+
attrs =
489+
case proto_org.allowed_id_providers do
490+
[_head | _tail] ->
491+
Map.put(
492+
attrs,
493+
:allowed_id_providers,
494+
Enum.join(proto_org.allowed_id_providers, ",")
495+
)
496+
497+
_ ->
498+
attrs
499+
end
500+
488501
case Guard.Store.Organization.update(organization, attrs) do
489502
{:ok, updated_org} ->
490503
%Organization.UpdateResponse{

β€Žguard/test/guard/grpc_servers/organization_server_test.exs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,6 +1530,55 @@ defmodule Guard.GrpcServers.OrganizationServerTest do
15301530
assert org.ip_allow_list == "192.168.1.1,192.168.1.2"
15311531
end
15321532

1533+
test "updates allowed_id_providers when non-empty list is provided", %{
1534+
grpc_channel: channel,
1535+
organization: organization
1536+
} do
1537+
assert organization.allowed_id_providers == "api_token,oidc"
1538+
1539+
req =
1540+
Organization.UpdateRequest.new(
1541+
organization:
1542+
Organization.Organization.new(
1543+
org_id: organization.id,
1544+
name: organization.name,
1545+
org_username: organization.username,
1546+
allowed_id_providers: ["okta"]
1547+
)
1548+
)
1549+
1550+
{:ok, response} = channel |> Organization.OrganizationService.Stub.update(req)
1551+
1552+
assert response.organization.allowed_id_providers == ["okta"]
1553+
1554+
updated_org = Guard.FrontRepo.get!(Guard.FrontRepo.Organization, organization.id)
1555+
assert updated_org.allowed_id_providers == "okta"
1556+
end
1557+
1558+
test "doesn't update allowed_id_providers when empty list is provided", %{
1559+
grpc_channel: channel,
1560+
organization: organization
1561+
} do
1562+
assert organization.allowed_id_providers == "api_token,oidc"
1563+
1564+
# Update with empty allowed_id_providers
1565+
request =
1566+
Organization.UpdateRequest.new(
1567+
organization:
1568+
Organization.Organization.new(
1569+
org_id: organization.id,
1570+
name: "Updated Organization",
1571+
org_username: "updated-org"
1572+
)
1573+
)
1574+
1575+
{:ok, response} = channel |> Organization.OrganizationService.Stub.update(request)
1576+
1577+
assert response.organization.allowed_id_providers == ["api_token", "oidc"]
1578+
updated_org = Guard.FrontRepo.get!(Guard.FrontRepo.Organization, organization.id)
1579+
assert updated_org.allowed_id_providers == "api_token,oidc"
1580+
end
1581+
15331582
test "returns error with invalid params", %{
15341583
grpc_channel: channel,
15351584
organization: organization

β€Žguard/test/support/factories/organization.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ defmodule Support.Factories.Organization do
88
open_source: false,
99
description: "Test Organization Description",
1010
website: "https://example.com",
11-
avatar_url: "https://example.com/avatar.png"
11+
avatar_url: "https://example.com/avatar.png",
12+
allowed_id_providers: "api_token,oidc"
1213
]
1314

1415
attrs = Keyword.merge(defaults, options) |> Enum.into(%{})

0 commit comments

Comments
Β (0)