Skip to content

Commit

Permalink
Fixes Haufe-Lexware/wicked.haufe.io#68 - allow longer application IDs…
Browse files Browse the repository at this point in the history
…, plus cap friendly name at 128 characters.
  • Loading branch information
DonMartin76 committed May 24, 2017
1 parent 38ce3d0 commit ead5c87
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions routes/applications.js
Expand Up @@ -120,8 +120,8 @@ var accessFlags = {

applications.isValidRedirectUri = function (redirectUri) {
return redirectUri &&
(redirectUri.indexOf('#') < 0) &&
(
(redirectUri.indexOf('#') < 0) &&
(
(redirectUri.startsWith('https://') && (redirectUri !== 'https://')) ||
(redirectUri.startsWith('http://localhost')) ||
(redirectUri.startsWith('http://127.0.0.1')) ||
Expand Down Expand Up @@ -220,14 +220,16 @@ applications.createApplication = function (app, res, loggedInUserId, appCreateIn
return res.status(403).jsonp({ message: 'Not allowed. Email address not validated.' });
if (redirectUri && !applications.isValidRedirectUri(redirectUri))
return res.status(400).jsonp({ message: 'redirectUri must be a https URI' });
if (!appCreateInfo.name || appCreateInfo.name.length < 1)
return res.status(400).jsonp({ message: 'Friendly name of application cannot be empty.' });

utils.withLockedUser(app, res, loggedInUserId, function () {
var regex = /^[a-zA-Z0-9\-_]+$/;

if (!regex.test(appId))
return res.status(400).jsonp({ message: 'Invalid application ID, allowed chars are: a-z, A-Z, -, _' });
if (appId.length < 4 || appId.length > 20)
return res.status(400).jsonp({ message: 'Invalid application ID, must have at least 4, max 20 characters.' });
if (appId.length < 4 || appId.length > 50)
return res.status(400).jsonp({ message: 'Invalid application ID, must have at least 4, max 50 characters.' });

// Check for dupes
for (var i = 0; i < appsIndex.length; ++i) {
Expand All @@ -239,7 +241,7 @@ applications.createApplication = function (app, res, loggedInUserId, appCreateIn
// Now we can add the application
var newApp = {
id: appId,
name: appCreateInfo.name,
name: appCreateInfo.name.substring(0, 128),
redirectUri: appCreateInfo.redirectUri,
owners: [
{
Expand Down Expand Up @@ -294,7 +296,7 @@ applications.createApplication = function (app, res, loggedInUserId, appCreateIn
applications.patchApplication = function (app, res, loggedInUserId, appId, appPatchInfo) {
debug('patchApplication(): ' + appId);
debug(appPatchInfo);

var appInfo = applications.loadApplication(app, appId);
if (!appInfo)
return res.status(404).jsonp({ message: 'Not found: ' + appId });
Expand All @@ -314,7 +316,7 @@ applications.patchApplication = function (app, res, loggedInUserId, appId, appPa
utils.withLockedApp(app, res, appId, function () {
// Update app
if (appPatchInfo.name)
appInfo.name = appPatchInfo.name;
appInfo.name = appPatchInfo.name.substring(0, 128);
if (redirectUri)
appInfo.redirectUri = redirectUri;

Expand Down Expand Up @@ -493,8 +495,8 @@ applications.addOwner = function (app, res, loggedInUserId, appId, ownerCreateIn
if (!userToAdd)
return res.status(400).jsonp({ message: 'Bad request. User with email "' + email + '" not found.' });
if (!(ownerRoles.OWNER == role ||
ownerRoles.COLLABORATOR == role ||
ownerRoles.READER == role))
ownerRoles.COLLABORATOR == role ||
ownerRoles.READER == role))
return res.status(400).jsonp({ message: 'Bad request. Unknown role "' + role + '".' });

// Does this user already know this application?
Expand Down

0 comments on commit ead5c87

Please sign in to comment.