From c340fe94f30eeaa05f3db08f930476b7ab277731 Mon Sep 17 00:00:00 2001
From: Karan Hotchandani <33024356+karanh37@users.noreply.github.com>
Date: Thu, 18 Jul 2024 23:23:50 +0530
Subject: [PATCH] saml reject token renewal (#17079)
---
.../SamlAuthenticator.test.tsx | 63 +++++++++++++++++++
.../AppAuthenticators/SamlAuthenticator.tsx | 4 +-
2 files changed, 66 insertions(+), 1 deletion(-)
create mode 100644 openmetadata-ui/src/main/resources/ui/src/components/Auth/AppAuthenticators/SamlAuthenticator.test.tsx
diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Auth/AppAuthenticators/SamlAuthenticator.test.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Auth/AppAuthenticators/SamlAuthenticator.test.tsx
new file mode 100644
index 00000000000..b30074e79e8
--- /dev/null
+++ b/openmetadata-ui/src/main/resources/ui/src/components/Auth/AppAuthenticators/SamlAuthenticator.test.tsx
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2024 Collate.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import { render, screen } from '@testing-library/react';
+import React from 'react';
+import { MemoryRouter } from 'react-router-dom';
+import { AuthenticatorRef } from '../AuthProviders/AuthProvider.interface';
+import SamlAuthenticator from './SamlAuthenticator';
+
+jest.mock('../../../hooks/useApplicationStore', () => {
+ return {
+ useApplicationStore: jest.fn(() => ({
+ authConfig: {},
+ getOidcToken: jest.fn().mockReturnValue({ isExpired: false }),
+ setOidcToken: jest.fn(),
+ })),
+ };
+});
+
+describe('Test SamlAuthenticator component', () => {
+ it('Checks if the SamlAuthenticator renders', async () => {
+ const onLogoutMock = jest.fn();
+ const authenticatorRef = null;
+ render(
+
+
+ ,
+ {
+ wrapper: MemoryRouter,
+ }
+ );
+ const children = screen.getByTestId('children');
+
+ expect(children).toBeInTheDocument();
+ });
+
+ it('Rejects promise when renew id token is called', async () => {
+ const onLogoutMock = jest.fn();
+ const authenticatorRef = React.createRef();
+
+ render(
+
+
+ ,
+ {
+ wrapper: MemoryRouter,
+ }
+ );
+
+ await expect(authenticatorRef.current?.renewIdToken()).rejects.toEqual(
+ 'SAML authenticator does not support token renewal'
+ );
+ });
+});
diff --git a/openmetadata-ui/src/main/resources/ui/src/components/Auth/AppAuthenticators/SamlAuthenticator.tsx b/openmetadata-ui/src/main/resources/ui/src/components/Auth/AppAuthenticators/SamlAuthenticator.tsx
index c53e8735806..5dc69416814 100644
--- a/openmetadata-ui/src/main/resources/ui/src/components/Auth/AppAuthenticators/SamlAuthenticator.tsx
+++ b/openmetadata-ui/src/main/resources/ui/src/components/Auth/AppAuthenticators/SamlAuthenticator.tsx
@@ -84,7 +84,9 @@ const SamlAuthenticator = forwardRef(
logout();
},
async renewIdToken() {
- return Promise.resolve('');
+ return Promise.reject(
+ 'SAML authenticator does not support token renewal'
+ );
},
}));