Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first draft of recaptcha validation #2

Merged
merged 6 commits into from
Apr 4, 2018

Conversation

reiddk
Copy link
Contributor

@reiddk reiddk commented Mar 27, 2018

No description provided.

@codecov
Copy link

codecov bot commented Mar 27, 2018

Codecov Report

Merging #2 into develop will increase coverage by 12.5%.
The diff coverage is 91.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##           develop      #2      +/-   ##
==========================================
+ Coverage       75%   87.5%   +12.5%     
==========================================
  Files            1       2       +1     
  Lines            8      32      +24     
  Branches         1       6       +5     
==========================================
+ Hits             6      28      +22     
- Misses           2       4       +2
Impacted Files Coverage Δ
src/app/validators/iscaptcha.validator.ts 91.66% <91.66%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a879af9...3cdd8a3. Read the comment docs.

Copy link
Member

@stonelasley stonelasley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good start. I think we can simplify into a single class so explore that and then let's get a unit test or two on your new validator class and then an E2E test.
https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha-v2-what-should-i-do

package.json Outdated
@@ -21,9 +21,11 @@
"@nestjs/websockets": "^4.5.8",
"class-transformer": "^0.1.9",
"class-validator": "^0.8.1",
"multer": "^1.3.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we using multer for?

secret: process.env.CAPTCHA_SECRET,
verbose: true
});
return new Promise((resolve, reject) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perfect, I think we can move this into a custom validation class and this is the implementation of the validate function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where one of my comments went, I'm doing something wrong apparently

import { MetadataStorageAndValidation } from './MetadataStorage';
import { getFromContainer } from './container';

export function IsCaptcha(validationOptions?: ValidationOptions) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can simplify this by creating a custom validation class that implements ValidatorConstraintInterface, this is documented in the README. You already have the validation function figured out but I think we can accomplish it without having to duplicate the files in our project.

resolve({});
});
} else {
const Recaptcha = require('recaptcha-verify');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than require this should probably be an import statement at the top I think import * as Recaptcha from 'recaptcha-verify'; should work.

@@ -1,4 +1,4 @@
import { Controller, Get, Post, Body } from '@nestjs/common';
import { Controller, Get, Post, Body, BadRequestException } from '@nestjs/common';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is BadRequestException being used?

@stonelasley stonelasley merged commit 73a06ca into develop Apr 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants