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

Load cacerts in sso #3073

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
21 changes: 21 additions & 0 deletions assets/js/pages/Login/Login.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,26 @@ describe('Login component', () => {
});
expect(loginButton).toBeVisible();
});

it('should display an error message is the SSO url is empty', async () => {
jest.spyOn(authConfig, 'isSingleSignOnEnabled').mockReturnValue(true);
jest.spyOn(authConfig, 'getSingleSignOnLoginUrl').mockReturnValue('');

const [StatefulLogin] = withState(<Login />, {
user: {
loggedIn: false,
authInProgress: false,
},
});

renderWithRouter(StatefulLogin);

await waitFor(() =>
screen.getByText(
`An error occurred while trying to access the Single Sign-On IDP host.`,
{ exact: false }
)
);
});
});
});
9 changes: 9 additions & 0 deletions assets/js/pages/Login/LoginSSO.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import React from 'react';
import Button from '@common/Button';

export default function LoginSSO({ singleSignOnUrl, error }) {
if (!singleSignOnUrl) {
return (
<span className="block text-sm font-medium">
An error occurred while trying to access the Single Sign-On IDP host.
Should the error persist, contact the administrator.
</span>
);
}

return (
<>
{error && (
Expand Down
5 changes: 5 additions & 0 deletions assets/js/pages/SSOCallback/SSOCallback.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'intersection-observer';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import { withState, renderWithRouterMatch } from '@lib/test-utils';
import * as authConfig from '@lib/auth/config';
import SSOCallback from './SSOCallback';

describe('SSOCallback component', () => {
Expand Down Expand Up @@ -50,6 +51,10 @@ describe('SSOCallback component', () => {
it('should display an error message if authentication fails', async () => {
const user = userEvent.setup();

jest
.spyOn(authConfig, 'getSingleSignOnLoginUrl')
.mockReturnValue('http://idp-url');

const [StatefulOidCallback] = withState(<SSOCallback />, {
user: {
authError: true,
Expand Down
2 changes: 2 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ if config_env() in [:prod, :demo] do
)
end

config :assent, http_adapter: {Assent.HTTPAdapter.Httpc, [ssl: [cacerts: cacerts]]}

config :trento, :oidc,
enabled: enable_oidc,
callback_url:
Expand Down
14 changes: 10 additions & 4 deletions lib/trento_web/controllers/page_controller.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule TrentoWeb.PageController do
use TrentoWeb, :controller

require Logger

def index(conn, _params) do
check_service_base_url = Application.fetch_env!(:trento, :checks_service)[:base_url]
charts_enabled = Application.fetch_env!(:trento, Trento.Charts)[:enabled]
Expand Down Expand Up @@ -57,15 +59,19 @@ defmodule TrentoWeb.PageController do
defp sso_details_for_provider(conn, provider) do
full_callback_url = Application.fetch_env!(:trento, provider)[:callback_url]
enrollment_provider = "#{provider}_local"
enrollment_url = ~p"/api/session/#{enrollment_provider}/callback"

%URI{path: callback_url} =
URI.parse(full_callback_url)

{:ok, login_url, _} =
PowAssent.Plug.authorize_url(conn, enrollment_provider, full_callback_url)
case PowAssent.Plug.authorize_url(conn, enrollment_provider, full_callback_url) do
{:ok, login_url, _} ->
{true, callback_url, login_url, enrollment_url}

enrollment_url = ~p"/api/session/#{enrollment_provider}/callback"
{:error, reason, _} ->
Logger.error("error getting SSO authorization url: #{inspect(reason)}")

{true, callback_url, login_url, enrollment_url}
{true, "", "", ""}
end
end
end
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule Trento.MixProject do
def application do
[
mod: {Trento.Application, []},
extra_applications: [:logger, :runtime_tools]
extra_applications: [:logger, :runtime_tools, :inets]
]
end

Expand Down
Loading