Skip to content

Commit 6c12482

Browse files
sammy-sandhuSimeranjeet Sandhu
andauthored
Latest code sync with P1 master branch (#57)
Co-authored-by: Simeranjeet Sandhu <simeransandhu@deloitte.com>
1 parent 717f93e commit 6c12482

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3813
-3169
lines changed

.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
// "ignoreDuringBuilds": true,
33
"extends": [
4-
"next/babel",
4+
"next",
55
"next/core-web-vitals",
66
"plugin:jsx-a11y/recommended"
77
],
@@ -11,6 +11,8 @@
1111
],
1212
"rules": {
1313
"react-hooks/exhaustive-deps": "off",
14+
"react-hooks/rules-of-hooks": "off",
15+
"react/no-deprecated": "off",
1416
"sort-imports-es6-autofix/sort-imports-es6": [
1517
2,
1618
{

.github/workflows/cd-workflow.yml

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
pull_request:
88
branches:
99
- main
10+
- dev
1011
types: [opened, synchronize, reopened]
1112

1213
jobs:
@@ -45,55 +46,22 @@ jobs:
4546
# # yarn
4647
# # yarn test --coverage
4748

48-
# sonarcloud:
49-
# name: SonarCloud
50-
# runs-on: ubuntu-latest
51-
# steps:
52-
# - uses: actions/checkout@v2
53-
# with:
54-
# fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
55-
# - name: SonarCloud Scan
56-
# uses: SonarSource/sonarcloud-github-action@master
57-
# env:
58-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
59-
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
60-
6149
build:
6250
# requires dependency from step above
6351
needs: code-test
6452
name: Build Docker Image
6553
runs-on: ubuntu-latest
66-
6754
steps:
6855
- name: Checkout Code
6956
uses: actions/checkout@v2
70-
71-
- name: Configure AWS credentials
72-
uses: aws-actions/configure-aws-credentials@v1
73-
with:
74-
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
75-
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
76-
aws-region: ${{ secrets.AWS_REGION }}
77-
78-
- name: Login to Amazon ECR
79-
id: login-ecr
80-
uses: aws-actions/amazon-ecr-login@v1
81-
with:
82-
mask-password: 'true'
83-
84-
- name: Build, tag, and push image to Amazon ECR
57+
- name: Docker login
8558
env:
86-
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
87-
ECR_REPOSITORY: ${{ secrets.ECR_REPO }}
88-
IMAGE_TAG: latest
59+
DOCKER_USER: ${{ secrets.DOCKER_USER }}
60+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
61+
run: |
62+
echo "Authenticate to Docker"
63+
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
64+
- name: Docker build
8965
run: |
90-
echo "Cloning private repository"
91-
git clone https://openlxp-host:${{ secrets.ACCESS_TOKEN }}@github.com/OpenLXP/openlxp-private.git
92-
echo "Private repository cloned successfully"
93-
echo "Copying .env file from openlxp-private to current working directory"
94-
cp ./openlxp-private/openlxp-xms-ui-env/.env .
95-
echo "Copied .env file successfully"
96-
echo "Starting docker build"
97-
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
98-
echo "Pushing image to ECR..."
99-
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
66+
echo "Start docker build"
67+
docker build . -t openlxp/openlxp-xms-ui

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# Dockerfile
22

33
# Install dependencies only when needed
4-
FROM node:14.18.1-alpine AS deps
4+
FROM node:18.20-alpine AS deps
55

66
# RUN apk add libc6-compat
77
WORKDIR /app
88
COPY . .
99
RUN yarn install
1010

1111
# Rebuild the source code only when needed
12-
FROM node:14.18.1-alpine AS builder
12+
FROM node:18.20-alpine AS builder
1313
WORKDIR /app
1414
COPY . .
1515
COPY --from=deps /app/node_modules ./node_modules
1616

1717
RUN yarn build
1818

1919
# Production image, copy all the files and run next
20-
FROM node:14.18.1-alpine AS runner
20+
FROM node:18.20-alpine AS runner
2121
WORKDIR /app
2222

2323
ENV NODE_ENV production

next.config.js

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,62 @@
1+
const { createSecureHeaders } = require("next-secure-headers");
2+
13
const nextConfig = {
24
reactStrictMode: true,
35
swcMinify: true,
6+
basePath: '/xms-ui',
7+
trailingSlash: true,
8+
49
// Adding policies:
510
async headers() {
611
return [
712
{
813
source: '/(.*)',
9-
headers: [
10-
{
11-
key: 'X-Frame-Options',
12-
value: 'DENY',
13-
},
14-
{
15-
key: 'X-Content-Type-Options',
16-
value: 'nosniff',
17-
},
18-
{
19-
key: 'Referrer-Policy',
20-
value: 'origin-when-cross-origin',
21-
},
22-
{
23-
key: 'Strict-Transport-Security',
24-
value: 'max-age=63072000; includeSubDomains; preload'
25-
},
26-
],
14+
headers: createSecureHeaders({
15+
contentSecurityPolicy: {
16+
directives: {
17+
defaultSrc: [
18+
"'self'",
19+
"https://ecc.staging.dso.mil",
20+
"https://ecc.staging.dso.mil/ecc-openlxp-xms",
21+
"https://ecc.staging.dso.mil/ecc-openlxp-xms-ui/",
22+
"https://ecc.apps.dso.mil/",
23+
"https://ecc.apps.dso.mil/ecc-openlxp-xms-ui/",
24+
"https://fonts.googleapis.com"
25+
],
26+
styleSrc: [
27+
"'self'",
28+
"https://ecc.staging.dso.mil",
29+
"https://ecc.staging.dso.mil/ecc-openlxp-xms",
30+
"https://ecc.staging.dso.mil/ecc-openlxp-xms-ui/",
31+
"https://ecc.apps.dso.mil/",
32+
"https://ecc.apps.dso.mil/ecc-openlxp-xms-ui/",
33+
"https://fonts.googleapis.com"
34+
],
35+
imgSrc: ["'self'",
36+
"data:",
37+
"data:*",
38+
],
39+
fontSrc: [
40+
"'self'",
41+
"https://fonts.gstatic.com"
42+
],
43+
frameAncestors: [
44+
"'self'",
45+
"https://ecc.apps.dso.mil/",
46+
"https://ecc.apps.dso.mil/ecc-openlxp-xms-ui/",
47+
"https://ecc.staging.dso.mil/ecc-openlxp-xms-ui/"
48+
]
49+
},
50+
frameGuard: "deny",
51+
noopen: "noopen",
52+
nosniff: "nosniff",
53+
xssProtection: "sanitize",
54+
referrerPolicy: "origin-when-cross-origin",
55+
}
56+
})
2757
},
2858
];
2959
},
3060
}
3161

32-
module.exports = nextConfig
62+
module.exports = nextConfig

package.json

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,61 @@
22
"name": "openlxp-xms-ui",
33
"version": "0.1.0",
44
"private": true,
5+
"homepage": ".",
56
"dependencies": {
7+
"@babel/helpers": "^7.26.0",
8+
"@babel/plugin-syntax-jsx": "^7.23.3",
9+
"@babel/runtime": "^7.26.10",
10+
"@craco/craco": "^6.1.2",
611
"@headlessui/react": "^1.3.0",
712
"@heroicons/react": "^1.0.6",
813
"@testing-library/jest-dom": "^5.14.1",
914
"@testing-library/react": "^12.1.2",
15+
"@testing-library/react-hooks": "^7.0.2",
1016
"@testing-library/user-event": "^12.1.10",
11-
"axios": "^0.21.1",
12-
"browserslist": "^4.16.5",
13-
"immer": "^9.0.6",
17+
"ajv": "6.12.3",
18+
"ansi-html": "0.0.8",
19+
"axios": "^1.8.2",
20+
"body-parser": "1.20.3",
21+
"braces": "3.0.3",
22+
"browserslist": "4.16.5",
23+
"cypress": "^13.6.3",
24+
"express": "4.21.2",
25+
"form-data": "4.0.4",
26+
"immer": "10.0.3",
1427
"ionicons": "^5.5.2",
15-
"jest": "^27.2.5",
16-
"moment": "^2.29.2",
17-
"next": "12.1.0",
28+
"jest": "^29.7.0",
29+
"jsdom": "^22.1.0",
30+
"jsonwebtoken": "9.0.0",
31+
"lodash": "^4.17.12",
32+
"micromatch": "4.0.8",
33+
"moment": "2.29.4",
34+
"next": "^14.2.25",
1835
"next-router-mock": "^0.9.11",
19-
"node-forge": "^1.3.0",
20-
"react": "^17.0.1",
21-
"react-dom": "^17.0.1",
36+
"next-secure-headers": "^2.2.0",
37+
"node-forge": "1.3.0",
38+
"path-to-regexp": "0.1.12",
39+
"postcss": "8.4.31",
40+
"qs": "6.5.3",
41+
"react": "18.2.0",
42+
"react-dom": "18",
2243
"react-query": "^3.39.3",
2344
"react-router-dom": "^5.2.0",
2445
"react-test-renderer": "^17.0.2",
25-
"tailwind": "^4.0.0",
26-
"web-vitals": "^1.0.1"
46+
"send": "0.19.0",
47+
"serve-static": "1.16.2",
48+
"tough-cookie": "4.1.3",
49+
"web-vitals": "^1.0.1",
50+
"ws": "6.2.3"
2751
},
2852
"scripts": {
2953
"dev": "next dev",
3054
"build": "next build",
3155
"start": "next start",
32-
"test": "jest --watch",
33-
"coverage": "jest --watchAll --coverage --verbose --noStackTrace --silent --maxWorkers=50%"
56+
"lint": "next lint",
57+
"test:unit": "jest --coverage --watchAll=false",
58+
"coverage": "jest --watchAll --coverage --verbose --noStackTrace --silent --maxWorkers=50%",
59+
"test:e2e-ci": "CYPRESS_BASE_URL=${ZAP_URL} npx cypress run --browser chrome --config-file cypress/config/pipeline.config.js"
3460
},
3561
"eslintConfig": {
3662
"extends": [
@@ -50,17 +76,20 @@
5076
]
5177
},
5278
"devDependencies": {
79+
"@babel/core": "^7.18.13",
80+
"@babel/eslint-parser": "^7.18.9",
81+
"@babel/plugin-proposal-private-property-in-object": "7.21.11",
82+
"@babel/plugin-transform-private-property-in-object": "7.22.11",
5383
"@testing-library/jest-dom": "^5.14.1",
5484
"@testing-library/react": "^12.1.2",
55-
"@testing-library/react-hooks": "^7.0.2",
5685
"autoprefixer": "^10.4.16",
5786
"eslint": "^8.6.0",
5887
"eslint-config-next": "12.0.7",
5988
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
6089
"identity-obj-proxy": "^3.0.0",
61-
"jest": "^27.2.5",
90+
"jest-environment-jsdom": "^29.7.0",
6291
"jest-mock-axios": "^4.4.1",
63-
"postcss": "^8.4.31",
64-
"tailwindcss": "^3.4.1"
92+
"react-csp": "^1.1.3",
93+
"tailwindcss": "^3.3.5"
6594
}
6695
}

src/__mocks__/authContextMock.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { useContext, createContext } from "react";
1+
import { createContext, useMemo } from "react";
22
export const AuthContext = createContext()
33
export const AuthContextWrapper = ({children}) => {
44
const login = jest.fn()
55
const register = jest.fn()
6-
return(<AuthContext.Provider value={{login, register}}>{children}</AuthContext.Provider>)
6+
const logindetails = useMemo(() => ({ login, register }),[]);
7+
return(
8+
<AuthContext.Provider value={logindetails}>
9+
{children}
10+
</AuthContext.Provider>)
711
}

src/__mocks__/mockSetUp.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ jest.mock('next/dist/client/router', () => require('next-router-mock'));
66
// mocking useStorage
77
jest.mock('@/hooks/useStorage', () => ({
88
useStorage: jest.fn(),
9+
useSessionStorage: () => ([null, jest.fn(), jest.fn()]),
910
}));
1011

1112

@@ -23,3 +24,13 @@ mockIntersectionObserver.mockReturnValue({
2324
disconnect: () => null,
2425
});
2526
window.IntersectionObserver = mockIntersectionObserver;
27+
28+
// mocking info mapping
29+
jest.mock("@/hooks/useInfoMappings", () => ({
30+
useInfoMappings: () => ({
31+
data: {
32+
course_title: "metadata.Course.CourseTitle",
33+
course_code: "metadata.Course.CourseCode",
34+
},
35+
}),
36+
}));

src/__tests__/components/Footer/Footer.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
22

3-
import { render, act, screen, fireEvent } from "@testing-library/react";
4-
import { unmountComponentAtNode } from "react-dom";
53
import { BrowserRouter, MemoryRouter, Route } from "react-router-dom";
4+
import { act, fireEvent, render, screen } from "@testing-library/react";
5+
import { createRoot } from 'react-dom/client'
6+
7+
import { unmountComponentAtNode } from "react-dom";
68

79
import Footer from "../../../components/Footer/Footer";
810

src/__tests__/components/Footer/FooterLink/FooterLink.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
import { render, act, screen, fireEvent } from "@testing-library/react";
4-
import { unmountComponentAtNode } from "react-dom";
53
import { BrowserRouter, MemoryRouter, Route } from "react-router-dom";
4+
import { act, fireEvent, render, screen } from "@testing-library/react";
5+
import { unmountComponentAtNode } from "react-dom";
66

77
import FooterLink from "../../../../components/Footer/FooterLink/FooterLink";
88

src/__tests__/components/Header/Header.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

3-
import { render, act, screen, fireEvent } from "@testing-library/react";
4-
import { unmountComponentAtNode } from "react-dom";
53
import { BrowserRouter, MemoryRouter, Route } from "react-router-dom";
4+
import { act, fireEvent, render, screen } from "@testing-library/react";
5+
import { unmountComponentAtNode } from "react-dom";
66

7-
import Header from "../../../components/Header/Header";
87
import { useAuthenticatedUser, useUnauthenticatedUser } from "@/__mocks__/predefinedMocks";
8+
import Header from "../../../components/Header/Header";
99
import singletonRouter from 'next/router';
1010

1111
let container = null;
@@ -110,7 +110,7 @@ describe("Header", () => {
110110
});
111111

112112
expect(singletonRouter).toMatchObject({
113-
asPath: '/login',
113+
asPath: '/',
114114
});
115115
});
116116

0 commit comments

Comments
 (0)