Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:cisagov/XFD into 113-create-mode…
Browse files Browse the repository at this point in the history
…ls-for-readysetcyber-data
  • Loading branch information
Matthew-Grayson committed Apr 9, 2024
2 parents f7f2ae5 + e8ea2f1 commit 13de3b7
Show file tree
Hide file tree
Showing 37 changed files with 2,501 additions and 107 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Playwright Tests
on:
deployment_status:
paths:
- playwright/**
- .github/workflows/playwright.yml
defaults:
run:
working-directory: ./playwright
env:
PW_XFD_2FA_ISSUER: ${{ secrets._PW_XFD_2FA_ISSUER }}
PW_XFD_2FA_SECRET: ${{ secrets.PW_XFD_2FA_SECRET }}
PW_XFD_PASSWORD: ${{ secrets.PW_XFD_PASSWORD }}
PW_XFD_URL: ${{ vars.PW_XFD_URL }}
PW_XFD_USER_ROLE: ${{ vars.PW_XFD_USER_ROLE }}
PW_XFD_USERNAME: ${{ secrets.PW_XFD_USERNAME }}

jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.41.2-jammy
if: github.event.deployment_status.state == 'success'
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm ci
- name: Run your tests
run: npx playwright test
env:
HOME: /root
93 changes: 39 additions & 54 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend/src/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ app.get('/', handlerToExpress(healthcheck));
app.post('/auth/login', handlerToExpress(auth.login));
app.post('/auth/callback', handlerToExpress(auth.callback));
app.post('/users/register', handlerToExpress(users.register));
app.post('/readysetcyber/register', handlerToExpress(users.RSCRegister));

const checkUserLoggedIn = async (req, res, next) => {
req.requestContext = {
Expand Down Expand Up @@ -276,7 +277,6 @@ app.use(
const authenticatedNoTermsRoute = express.Router();
authenticatedNoTermsRoute.use(checkUserLoggedIn);
authenticatedNoTermsRoute.get('/users/me', handlerToExpress(users.me));
// authenticatedNoTermsRoute.post('/users/register', handlerToExpress(users.register));
authenticatedNoTermsRoute.post(
'/users/me/acceptTerms',
handlerToExpress(users.acceptTerms)
Expand Down
73 changes: 73 additions & 0 deletions backend/src/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,30 @@ If you encounter any difficulties, please feel free to reply to this email (or s
);
};

const sendRSCInviteEmail = async (email: string) => {
const staging = process.env.NODE_ENV !== 'production';

await sendEmail(
email,
'ReadySetCyber Dashboard Invitation',
`Hi there,
You've been invited to join ReadySetCyber Dashboard. To accept the invitation and start using your Dashboard, sign on at ${process.env.FRONTEND_DOMAIN}/readysetcyber/create-account.
Crossfeed access instructions:
1. Visit ${process.env.FRONTEND_DOMAIN}/readysetcyber/create-account.
2. Select "Create Account."
3. Enter your email address and a new password for Crossfeed.
4. A confirmation code will be sent to your email. Enter this code when you receive it.
5. You will be prompted to enable MFA. Scan the QR code with an authenticator app on your phone, such as Microsoft Authenticator. Enter the MFA code you see after scanning.
6. After configuring your account, you will be redirected to Crossfeed.
For more information on using Crossfeed, view the Crossfeed user guide at https://docs.crossfeed.cyber.dhs.gov/user-guide/quickstart/.
If you encounter any difficulties, please feel free to reply to this email (or send an email to ${process.env.CROSSFEED_SUPPORT_EMAIL_REPLYTO}).`
);
};
/**
* @swagger
*
Expand Down Expand Up @@ -892,3 +916,52 @@ export const updateV2 = wrapHandler(async (event) => {
}
return NotFound;
});

/**
* @swagger
*
* /readysetcyber/register:
* post:
* description: New ReadySetCyber user registration.
* tags:
* - RSCUsers
*/
export const RSCRegister = wrapHandler(async (event) => {
const body = await validateBody(NewUser, event.body);
const newRSCUser = {
firstName: body.firstName,
lastName: body.lastName,
email: body.email.toLowerCase(),
userType: UserType.READY_SET_CYBER
};

await connectToDatabase();

// Check if user already exists
let user = await User.findOne({
email: newRSCUser.email
});
if (user) {
console.log('User already exists.');
return {
statusCode: 422,
body: 'User email already exists. Registration failed.'
};
// Create if user does not exist
} else {
user = await User.create(newRSCUser);
await User.save(user);
// Send email notification
if (process.env.IS_LOCAL!) {
console.log('Cannot send invite email while running on local.');
} else {
await sendRSCInviteEmail(user.email);
}
}

const savedUser = await User.findOne(user.id);
return {
statusCode: 200,
body: JSON.stringify(savedUser)
};
});
4 changes: 4 additions & 0 deletions backend/test/assessments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { expect, test } from '@jest/globals';
test('dummy test', () => {
expect(true).toBe(true);
});
2 changes: 1 addition & 1 deletion backend/worker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ numpy==1.24.3
pandas==2.1.4
phonenumbers==8.13.8
pip-tools==7.1.0
pipreqs==0.4.11
pipreqs==0.4.12
psycopg2-binary==2.9.5
pyproject_hooks==1.0.0
pytest==7.3.0
Expand Down
Loading

0 comments on commit 13de3b7

Please sign in to comment.