Browse Source

fix lint error

utsushiiro 6 years ago
parent
commit
7a71b02b85
3 changed files with 37 additions and 36 deletions
  1. 5 5
      src/server/routes/admin.js
  2. 1 1
      src/server/service/config-manager.js
  3. 31 30
      src/server/service/passport.js

+ 5 - 5
src/server/routes/admin.js

@@ -782,8 +782,8 @@ module.exports = function(crowi, app) {
    * validate setting form values for SAML
    *
    * The following are checked.
-   * 
-   * - For the value of each mandatory items, 
+   *
+   * - For the value of each mandatory items,
    *     check whether it from the environment variables is empty and form value to update it is empty.
    * - validate the syntax of a attribute-based login control rule
    */
@@ -796,11 +796,11 @@ module.exports = function(crowi, app) {
       }
     }
 
-    const rule = form.settingForm["security:passport-saml:ABLCRule"];
+    const rule = form.settingForm['security:passport-saml:ABLCRule'];
     // Empty string disables attribute-based login control.
     // So, when rule is empty string, validation is passed.
-    if (rule !== "" && rule != null && crowi.passportService.parseABLCRule(rule) === null) {
-      form.errors.push("Rule syntax is invalid");
+    if (rule !== '' && rule != null && crowi.passportService.parseABLCRule(rule) === null) {
+      form.errors.push('Rule syntax is invalid');
     }
   }
 

+ 1 - 1
src/server/service/config-manager.js

@@ -15,7 +15,7 @@ const KEYS_FOR_SAML_USE_ONLY_ENV_OPTION = [
   'security:passport-saml:attrMapFirstName',
   'security:passport-saml:attrMapLastName',
   'security:passport-saml:cert',
-  'security:passport-saml:ABLCRule'
+  'security:passport-saml:ABLCRule',
 ];
 
 class ConfigManager {

+ 31 - 30
src/server/service/passport.js

@@ -611,41 +611,41 @@ class PassportService {
     if (expr === null) {
       return false;
     }
-    debug({"Parsed Rule": JSON.stringify(expr, null, 2)});
+    debug({ 'Parsed Rule': JSON.stringify(expr, null, 2) });
 
     const attributes = this.extractAttributesFromSAMLResponse(response);
-    debug({"Extracted Attributes": JSON.stringify(attributes, null, 2)});
-
-    let evaluated_expr = false
-    for (const or_op of expr) {
-      let evaluated_or_op = true;
-      for (const and_op of or_op) {
-        if (attributes[and_op[0]] == null) {
-          evaluated_or_op = false
+    debug({ 'Extracted Attributes': JSON.stringify(attributes, null, 2) });
+
+    let evaluatedExpr = false;
+    for (const orOp of expr) {
+      let evaluatedOrOp = true;
+      for (const andOp of orOp) {
+        if (attributes[andOp[0]] == null) {
+          evaluatedOrOp = false;
           break;
         }
-        evaluated_or_op = evaluated_or_op && attributes[and_op[0]].includes(and_op[1])
+        evaluatedOrOp = evaluatedOrOp && attributes[andOp[0]].includes(andOp[1]);
       }
-      evaluated_expr = evaluated_expr || evaluated_or_op;
+      evaluatedExpr = evaluatedExpr || evaluatedOrOp;
     }
 
-    return evaluated_expr;
+    return evaluatedExpr;
   }
 
   /**
    * Parse a rule string for the attribute-based login control
-   * 
+   *
    * The syntax rules are as follows.
    * <attr> and <value> are any characters except "|", "&", "=".
-   * 
+   *
    * ## Syntax
    *    <expr>   ::= <or_op> | <or_op> "|" <expr>
    *    <or_op>  ::= <and_op> | <and_op> "&" <or_op>
    *    <and_op> ::= <attr> "=" <value>
-   * 
+   *
    * ## Example
    *  In:  "Department = A | Department = B & Position = Leader"
-   *  Out: 
+   *  Out:
    *    [
    *      [
    *        ["Department", "A"]
@@ -655,18 +655,18 @@ class PassportService {
    *        ["Position","Leader"]
    *      ]
    *    ]
-   * 
+   *
    *   In:  Invalid syntax string like a "This is a & bad & rule string."
    *   Out: null
    */
   parseABLCRule(rule) {
-    let expr = rule.split("|");
-    expr = expr.map(or_op => or_op.trim().split("&"));
-    expr = expr.map(or_op => or_op.map(and_op => and_op.trim().split("=")));
-    expr = expr.map(or_op => or_op.map(and_op => and_op.map(v => v.trim())));
-    for (const or_op of expr) {
-      for (const and_op of or_op) {
-        if (and_op.length !== 2) {
+    let expr = rule.split('|');
+    expr = expr.map(orOp => orOp.trim().split('&'));
+    expr = expr.map(orOp => orOp.map(andOp => andOp.trim().split('=')));
+    expr = expr.map(orOp => orOp.map(andOp => andOp.map(v => v.trim())));
+    for (const orOp of expr) {
+      for (const andOp of orOp) {
+        if (andOp.length !== 2) {
           return null;
         }
       }
@@ -677,9 +677,9 @@ class PassportService {
 
   /**
    * Extract attributes from a SAML response
-   * 
+   *
    * The format of extracted attributes is the following.
-   * 
+   *
    * {
    *    "attribute_name1": ["value1", "value2", ...],
    *    "attribute_name2": ["value1", "value2", ...],
@@ -700,14 +700,15 @@ class PassportService {
     const result = {};
     for (const attribute of attributes) {
       const name = attribute.$.Name;
-      const attributeValues = attribute.AttributeValue.map(v => v._)
+      const attributeValues = attribute.AttributeValue.map(v => v._);
       if (result[name] == null) {
         result[name] = attributeValues;
-      }else {
-        result[name] = result[name].concat(attributeValues)
+      }
+      else {
+        result[name] = result[name].concat(attributeValues);
       }
     }
-    
+
     return result;
   }