Skip to content

Removed is.js #108

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

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/grant-types/abstract-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const InvalidArgumentError = require('../errors/invalid-argument-error');
const InvalidScopeError = require('../errors/invalid-scope-error');
const Promise = require('bluebird');
const promisify = require('promisify-any').use(Promise);
const is = require('../validator/is');
const isFormat = require('@node-oauth/formats');
const tokenUtil = require('../utils/token-util');

/**
Expand Down Expand Up @@ -83,7 +83,7 @@ AbstractGrantType.prototype.getRefreshTokenExpiresAt = function() {
*/

AbstractGrantType.prototype.getScope = function(request) {
if (!is.nqschar(request.body.scope)) {
if (!isFormat.nqschar(request.body.scope)) {
throw new InvalidArgumentError('Invalid parameter: `scope`');
}

Expand Down
8 changes: 4 additions & 4 deletions lib/grant-types/authorization-code-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const InvalidRequestError = require('../errors/invalid-request-error');
const Promise = require('bluebird');
const promisify = require('promisify-any').use(Promise);
const ServerError = require('../errors/server-error');
const is = require('../validator/is');
const isFormat = require('@node-oauth/formats');
const util = require('util');

/**
Expand Down Expand Up @@ -85,7 +85,7 @@ AuthorizationCodeGrantType.prototype.getAuthorizationCode = function(request, cl
throw new InvalidRequestError('Missing parameter: `code`');
}

if (!is.vschar(request.body.code)) {
if (!isFormat.vschar(request.body.code)) {
throw new InvalidRequestError('Invalid parameter: `code`');
}
return promisify(this.model.getAuthorizationCode, 1).call(this.model, request.body.code)
Expand Down Expand Up @@ -114,7 +114,7 @@ AuthorizationCodeGrantType.prototype.getAuthorizationCode = function(request, cl
throw new InvalidGrantError('Invalid grant: authorization code has expired');
}

if (code.redirectUri && !is.uri(code.redirectUri)) {
if (code.redirectUri && !isFormat.uri(code.redirectUri)) {
throw new InvalidGrantError('Invalid grant: `redirect_uri` is not a valid URI');
}

Expand All @@ -140,7 +140,7 @@ AuthorizationCodeGrantType.prototype.validateRedirectUri = function(request, cod

const redirectUri = request.body.redirect_uri || request.query.redirect_uri;

if (!is.uri(redirectUri)) {
if (!isFormat.uri(redirectUri)) {
throw new InvalidRequestError('Invalid request: `redirect_uri` is not a valid URI');
}

Expand Down
6 changes: 3 additions & 3 deletions lib/grant-types/password-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const InvalidGrantError = require('../errors/invalid-grant-error');
const InvalidRequestError = require('../errors/invalid-request-error');
const Promise = require('bluebird');
const promisify = require('promisify-any').use(Promise);
const is = require('../validator/is');
const isFormat = require('@node-oauth/formats');
const util = require('util');

/**
Expand Down Expand Up @@ -80,11 +80,11 @@ PasswordGrantType.prototype.getUser = function(request) {
throw new InvalidRequestError('Missing parameter: `password`');
}

if (!is.uchar(request.body.username)) {
if (!isFormat.uchar(request.body.username)) {
throw new InvalidRequestError('Invalid parameter: `username`');
}

if (!is.uchar(request.body.password)) {
if (!isFormat.uchar(request.body.password)) {
throw new InvalidRequestError('Invalid parameter: `password`');
}

Expand Down
4 changes: 2 additions & 2 deletions lib/grant-types/refresh-token-grant-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const InvalidRequestError = require('../errors/invalid-request-error');
const Promise = require('bluebird');
const promisify = require('promisify-any').use(Promise);
const ServerError = require('../errors/server-error');
const is = require('../validator/is');
const isFormat = require('@node-oauth/formats');
const util = require('util');

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ RefreshTokenGrantType.prototype.getRefreshToken = function(request, client) {
throw new InvalidRequestError('Missing parameter: `refresh_token`');
}

if (!is.vschar(request.body.refresh_token)) {
if (!isFormat.vschar(request.body.refresh_token)) {
throw new InvalidRequestError('Invalid parameter: `refresh_token`');
}

Expand Down
10 changes: 5 additions & 5 deletions lib/handlers/authorize-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Request = require('../request');
const Response = require('../response');
const ServerError = require('../errors/server-error');
const UnauthorizedClientError = require('../errors/unauthorized-client-error');
const is = require('../validator/is');
const isFormat = require('@node-oauth/formats');
const tokenUtil = require('../utils/token-util');
const url = require('url');

Expand Down Expand Up @@ -171,13 +171,13 @@ AuthorizeHandler.prototype.getClient = function(request) {
throw new InvalidRequestError('Missing parameter: `client_id`');
}

if (!is.vschar(clientId)) {
if (!isFormat.vschar(clientId)) {
throw new InvalidRequestError('Invalid parameter: `client_id`');
}

const redirectUri = request.body.redirect_uri || request.query.redirect_uri;

if (redirectUri && !is.uri(redirectUri)) {
if (redirectUri && !isFormat.uri(redirectUri)) {
throw new InvalidRequestError('Invalid request: `redirect_uri` is not a valid URI');
}
return promisify(this.model.getClient, 2).call(this.model, clientId, null)
Expand Down Expand Up @@ -230,7 +230,7 @@ AuthorizeHandler.prototype.validateScope = function(user, client, scope) {
AuthorizeHandler.prototype.getScope = function(request) {
const scope = request.body.scope || request.query.scope;

if (!is.nqschar(scope)) {
if (!isFormat.nqschar(scope)) {
throw new InvalidScopeError('Invalid parameter: `scope`');
}

Expand All @@ -245,7 +245,7 @@ AuthorizeHandler.prototype.getState = function(request) {
const state = request.body.state || request.query.state;
const stateExists = state && state.length > 0;
const stateIsValid = stateExists
? is.vschar(state)
? isFormat.vschar(state)
: this.allowEmptyState;

if (!stateIsValid) {
Expand Down
8 changes: 4 additions & 4 deletions lib/handlers/token-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TokenModel = require('../models/token-model');
const UnauthorizedClientError = require('../errors/unauthorized-client-error');
const UnsupportedGrantTypeError = require('../errors/unsupported-grant-type-error');
const auth = require('basic-auth');
const is = require('../validator/is');
const isFormat = require('@node-oauth/formats');

/**
* Grant types.
Expand Down Expand Up @@ -123,11 +123,11 @@ TokenHandler.prototype.getClient = function(request, response) {
throw new InvalidRequestError('Missing parameter: `client_secret`');
}

if (!is.vschar(credentials.clientId)) {
if (!isFormat.vschar(credentials.clientId)) {
throw new InvalidRequestError('Invalid parameter: `client_id`');
}

if (credentials.clientSecret && !is.vschar(credentials.clientSecret)) {
if (credentials.clientSecret && !isFormat.vschar(credentials.clientSecret)) {
throw new InvalidRequestError('Invalid parameter: `client_secret`');
}

Expand Down Expand Up @@ -203,7 +203,7 @@ TokenHandler.prototype.handleGrantType = function(request, client) {
throw new InvalidRequestError('Missing parameter: `grant_type`');
}

if (!is.nchar(grantType) && !is.uri(grantType)) {
if (!isFormat.nchar(grantType) && !isFormat.uri(grantType)) {
throw new InvalidRequestError('Invalid parameter: `grant_type`');
}

Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"lib"
],
"dependencies": {
"@node-oauth/formats": "^1.0.0",
"basic-auth": "2.0.1",
"bluebird": "3.7.2",
"promisify-any": "2.0.1",
Expand All @@ -44,6 +45,7 @@
"pretest": "./node_modules/.bin/eslint lib test index.js",
"test": "NODE_ENV=test ./node_modules/.bin/mocha 'test/**/*_test.js'",
"test-debug": "NODE_ENV=test ./node_modules/.bin/mocha --inspect --debug-brk 'test/**/*_test.js'",
"test:watch": "NODE_ENV=test ./node_modules/.bin/mocha --watch 'test/**/*_test.js'",
"test:coverage": "NODE_ENV=test nyc --reporter=html --reporter=text ./node_modules/.bin/mocha 'test/**/*_test.js'",
"lint": "npx eslint .",
"lint:fix": "npx eslint . --fix"
Expand Down
127 changes: 0 additions & 127 deletions test/unit/validator/is_test.js

This file was deleted.