Skip to content
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

Fix sso login #1361

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/core/lib/core/services/users.ex
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,13 @@ defmodule Core.Services.Users do
"""
@spec bootstrap_user(Core.OAuth.method, map) :: user_resp
def bootstrap_user(service, %{email: email} = attrs) do
case get_user_by_email(email) do
nil ->
case {service, get_user_by_email(email)} do
{_, nil} ->
attrs
|> Map.merge(login_args(service))
|> Map.put(:password, Ecto.UUID.generate())
|> create_user()
%User{login_method: ^service} = user ->
{service, %User{login_method: svc} = user} when service == :sso or service == svc ->
update_user(login_args(service), user)
_ -> {:error, "you don't have login with #{service} enabled"}
end
Expand Down
12 changes: 10 additions & 2 deletions apps/core/test/services/users_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ defmodule Core.Services.UsersTest do
end
end

describe "#bootstrap_users/2" do
describe "#bootstrap_user/2" do
test "it will create new users and set login method" do
{:ok, user} = Users.bootstrap_user(:google, %{email: "someone@gmail.com", name: "New User"})

Expand All @@ -532,11 +532,19 @@ defmodule Core.Services.UsersTest do
assert upd.login_method == :google
end

test "it will not allow logins w/o login method set" do
test "it will not allow logins w/o correct login method set" do
user = insert(:user)

{:error, _} = Users.bootstrap_user(:google, %{email: user.email})
end

test "it will allow sso logins w/ whatever login method set" do
user = insert(:user)

{:ok, upd} = Users.bootstrap_user(:sso, %{email: user.email})

assert upd.id == user.id
end
end

describe "#create_trust_relationship" do
Expand Down
2 changes: 1 addition & 1 deletion apps/graphql/test/mutations/user_mutation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ defmodule GraphQl.UserMutationTest do
end

test "it will fail on invalid captchas" do
{:ok, user} = Users.create_user(%{
{:ok, _} = Users.create_user(%{
name: "Michael Guarino",
email: "mjg@plural.sh",
password: "super strong password"
Expand Down
Loading