Skip to content

Commit 63d94e8

Browse files
Abhaysoft-incarkid15r
authored andcommitted
fixes OWASP#2124: Refactored environment variable handling from credentials.ts to env.server.ts and env.client.ts (OWASP#2125)
* splitted env vars into env.client and env.server and updated the imports * removed credentials.ts * Update code --------- Co-authored-by: Arkadii Yakovets <arkadii.yakovets@owasp.org>
1 parent 021beee commit 63d94e8

File tree

19 files changed

+31
-32
lines changed

19 files changed

+31
-32
lines changed

frontend/__tests__/unit/components/CardDetailsPage.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jest.mock('@fortawesome/react-fontawesome', () => ({
6868
}) => <span data-testid={`icon-${icon.iconName}`} className={className} {...props} />,
6969
}))
7070

71-
jest.mock('utils/credentials', () => ({
71+
jest.mock('utils/env.client', () => ({
7272
IS_PROJECT_HEALTH_ENABLED: true,
7373
}))
7474

frontend/__tests__/unit/components/Footer.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jest.mock('utils/constants', () => ({
9595
],
9696
}))
9797

98-
jest.mock('utils/credentials', () => ({
98+
jest.mock('utils/env.client', () => ({
9999
ENVIRONMENT: 'production',
100100
RELEASE_VERSION: '1.2.3',
101101
}))

frontend/__tests__/unit/pages/Login.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jest.mock('next/navigation', () => ({
1515
jest.mock('@heroui/toast', () => ({
1616
addToast: jest.fn(),
1717
}))
18-
jest.mock('utils/credentials', () => ({
19-
isGithubAuthEnabled: jest.fn(() => true),
18+
jest.mock('utils/env.server', () => ({
19+
IS_GITHUB_AUTH_ENABLED: true,
2020
}))
2121
describe('LoginPage', () => {
2222
const pushMock = jest.fn()

frontend/next.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { withSentryConfig } from '@sentry/nextjs'
22
import type { NextConfig } from 'next'
3-
import { SENTRY_AUTH_TOKEN } from 'utils/credentials'
3+
import { SENTRY_AUTH_TOKEN } from 'utils/env.server'
44

55
const isLocal = process.env.NEXT_PUBLIC_ENVIRONMENT === 'local'
66

frontend/src/app/api/auth/[...nextauth]/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import GitHubProvider from 'next-auth/providers/github'
33
import { apolloClient } from 'server/apolloClient'
44
import { IS_PROJECT_LEADER_QUERY, IS_MENTOR_QUERY } from 'server/queries/mentorshipQueries'
55
import { ExtendedProfile, ExtendedSession } from 'types/auth'
6-
import { isGithubAuthEnabled } from 'utils/credentials'
6+
import { IS_GITHUB_AUTH_ENABLED } from 'utils/env.server'
77

88
async function checkIfProjectLeader(login: string): Promise<boolean> {
99
try {
@@ -35,7 +35,7 @@ async function checkIfMentor(login: string): Promise<boolean> {
3535

3636
const providers = []
3737

38-
if (isGithubAuthEnabled()) {
38+
if (IS_GITHUB_AUTH_ENABLED) {
3939
providers.push(
4040
GitHubProvider({
4141
clientId: process.env.NEXT_SERVER_GITHUB_CLIENT_ID,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { isGithubAuthEnabled } from 'utils/credentials'
1+
import { IS_GITHUB_AUTH_ENABLED } from 'utils/env.server'
22
import LoginPageContent from 'components/LoginPageContent'
33

44
export default function LoginPage() {
5-
return <LoginPageContent isGitHubAuthEnabled={isGithubAuthEnabled()} />
5+
return <LoginPageContent isGitHubAuthEnabled={IS_GITHUB_AUTH_ENABLED} />
66
}

frontend/src/app/layout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import type { Metadata } from 'next'
33
import { Geist, Geist_Mono } from 'next/font/google'
44
import React from 'react'
55
import { Providers } from 'wrappers/provider'
6-
import { GTM_ID, isGithubAuthEnabled } from 'utils/credentials'
6+
import { GTM_ID } from 'utils/env.client'
7+
import { IS_GITHUB_AUTH_ENABLED } from 'utils/env.server'
78
import AutoScrollToTop from 'components/AutoScrollToTop'
89
import BreadCrumbs from 'components/BreadCrumbs'
910
import Footer from 'components/Footer'
@@ -69,7 +70,7 @@ export default function RootLayout({
6970
>
7071
<Providers>
7172
<AutoScrollToTop />
72-
<Header isGitHubAuthEnabled={isGithubAuthEnabled()} />
73+
<Header isGitHubAuthEnabled={IS_GITHUB_AUTH_ENABLED} />
7374
<BreadCrumbs />
7475
{children}
7576
<Footer />

frontend/src/app/projects/dashboard/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { notFound } from 'next/navigation'
22
import React from 'react'
3-
import { isGithubAuthEnabled } from 'utils/credentials'
3+
import { IS_GITHUB_AUTH_ENABLED } from 'utils/env.server'
44
import DashboardWrapper from 'components/DashboardWrapper'
55
import FontLoaderWrapper from 'components/FontLoaderWrapper'
66
import ProjectsDashboardNavBar from 'components/ProjectsDashboardNavBar'
77

88
const ProjectsHealthDashboardLayout: React.FC<{ readonly children: React.ReactNode }> = ({
99
children,
1010
}) => {
11-
if (!isGithubAuthEnabled()) {
11+
if (!IS_GITHUB_AUTH_ENABLED) {
1212
notFound()
1313
}
1414
return (

frontend/src/app/settings/api-keys/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { notFound, redirect } from 'next/navigation'
22
import { getServerSession } from 'next-auth'
33
import React from 'react'
4-
import { isGithubAuthEnabled } from 'utils/credentials'
4+
import { IS_GITHUB_AUTH_ENABLED } from 'utils/env.server'
55

66
export default async function ApiKeysLayout({ children }: Readonly<{ children: React.ReactNode }>) {
7-
if (!isGithubAuthEnabled()) {
7+
if (!IS_GITHUB_AUTH_ENABLED) {
88
notFound()
99
}
1010
const session = await getServerSession()

frontend/src/components/CardDetailsPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { useRouter } from 'next/navigation'
1414
import { useSession } from 'next-auth/react'
1515
import type { ExtendedSession } from 'types/auth'
1616
import type { DetailsCardProps } from 'types/card'
17-
import { IS_PROJECT_HEALTH_ENABLED } from 'utils/credentials'
17+
import { IS_PROJECT_HEALTH_ENABLED } from 'utils/env.client'
1818
import { scrollToAnchor } from 'utils/scrollToAnchor'
1919
import { getSocialIcon } from 'utils/urlIconMappings'
2020
import AnchorTitle from 'components/AnchorTitle'
@@ -87,7 +87,7 @@ const DetailsCard = ({
8787
) && (
8888
<button
8989
type="button"
90-
className="flex items-center justify-center gap-2 text-nowrap rounded-md border border-[#0D6EFD] bg-transparent px-2 py-2 text-[#0D6EFD] text-blue-600 transition-all hover:bg-[#0D6EFD] hover:text-white dark:border-sky-600 dark:text-sky-600 dark:hover:bg-sky-100"
90+
className="flex items-center justify-center gap-2 text-nowrap rounded-md border border-[#0D6EFD] bg-transparent px-2 py-2 text-[#0D6EFD] transition-all hover:bg-[#0D6EFD] hover:text-white dark:border-sky-600 dark:text-sky-600 dark:hover:bg-sky-100"
9191
onClick={() => {
9292
router.push(`${window.location.pathname}/edit`)
9393
}}

0 commit comments

Comments
 (0)