World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#14957] The /configs endpoint not requires authentication (#14958)
Qian Xia43893ab6495d
diff --git a/web-v2/web/src/lib/api/auth/index.js b/web-v2/web/src/lib/api/auth/index.jsindex 7e22d23885..a02aecc33f 100644--- a/web-v2/web/src/lib/api/auth/index.js+++ b/web-v2/web/src/lib/api/auth/index.js@@ -21,9 +21,12 @@ import { defHttp } from '@/lib/utils/axios'import { ContentTypeEnum } from '@/lib/enums/httpEnum'export const getAuthConfigsApi = () => {- return defHttp.get({- url: '/configs'- })+ return defHttp.get(+ {+ url: '/configs'+ },+ { withToken: false }+ )}export const getAuthMeApi = () => {diff --git a/web-v2/web/src/lib/api/auth/index.test.js b/web-v2/web/src/lib/api/auth/index.test.jsnew file mode 100644index 0000000000..e289068468--- /dev/null+++ b/web-v2/web/src/lib/api/auth/index.test.js@@ -0,0 +1,74 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one+ * or more contributor license agreements. See the NOTICE file+ * distributed with this work for additional information+ * regarding copyright ownership. The ASF licenses this file+ * to you 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 { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { getAuthConfigsApi } from '@/lib/api/auth'+import { oauthProviderFactory } from '@/lib/auth/providers/factory'+import { defHttp } from '@/lib/utils/axios'++describe('getAuthConfigsApi', () => {+ let adapter+ let originalAdapter+ let getAccessToken++ beforeEach(() => {+ localStorage.clear()+ sessionStorage.clear()++ const axiosInstance = defHttp.getAxios()+ originalAdapter = axiosInstance.defaults.adapter+ adapter = vi.fn(async config => ({+ data: {},+ status: 200,+ statusText: 'OK',+ headers: {},+ config+ }))+ axiosInstance.defaults.adapter = adapter+ getAccessToken = vi.spyOn(oauthProviderFactory, 'getAccessToken').mockResolvedValue('oauth-token')+ })++ afterEach(() => {+ defHttp.getAxios().defaults.adapter = originalAdapter+ vi.restoreAllMocks()+ localStorage.clear()+ sessionStorage.clear()+ })++ it.each(['oauth', 'basic', 'simple', null])('omits Authorization for auth type %s', async authType => {+ if (authType) {+ localStorage.setItem('authType', authType)+ }++ if (authType === 'basic') {+ sessionStorage.setItem('accessToken', 'basic-token')+ } else if (authType === 'simple') {+ sessionStorage.setItem('simpleAuthUser', JSON.stringify({ name: 'simple-user' }))+ } else if (authType === null) {+ localStorage.setItem('accessToken', 'stale-token')+ }++ await getAuthConfigsApi()++ const requestConfig = adapter.mock.calls[0][0]+ expect(requestConfig.url).toBe('/configs')+ expect(requestConfig.headers.get('Authorization')).toBeUndefined()+ expect(getAccessToken).not.toHaveBeenCalled()+ })+})diff --git a/web-v2/web/src/lib/utils/axios/index.js b/web-v2/web/src/lib/utils/axios/index.jsindex 1573a5c207..708f0ddb9c 100644--- a/web-v2/web/src/lib/utils/axios/index.js+++ b/web-v2/web/src/lib/utils/axios/index.js@@ -175,6 +175,10 @@ const transform = {requestInterceptors: async (config, options) => {// ** Pre-Request Configuration Handling+ if (config.requestOptions?.withToken === false) {+ return config+ }+// Skip token retrieval for GitHub API calls entirelyif (config.url === githubApis.GET) {return config@@ -189,7 +193,7 @@ const transform = {// OAuth auth: use Bearer token from OAuth providerconst token = await oauthProviderFactory.getAccessToken()- if (token && config?.requestOptions?.withToken !== false) {+ if (token) {// ** jwt tokenconfig.headers.Authorization = options.authenticationScheme? `${options.authenticationScheme} ${token}`@@ -204,7 +208,7 @@ const transform = {} else if (authType === 'basic') {// Basic auth: use token from sessionStorageconst token = sessionStorage.getItem('accessToken')- if (token && config?.requestOptions?.withToken !== false) {+ if (token) {const isFullAuthHeader = token.startsWith('Basic ') || token.startsWith('Bearer ')config.headers.Authorization =@@ -215,7 +219,7 @@ const transform = {// Fall back to persisted auth artifacts to avoid spurious 401s.// localStorage.accessToken indicates a prior OAuth session (simple auth doesn't persist tokens).const persistedToken = localStorage.getItem('accessToken')- if (persistedToken && config?.requestOptions?.withToken !== false) {+ if (persistedToken) {config.headers.Authorization = options.authenticationScheme? `${options.authenticationScheme} ${persistedToken}`: persistedToken