소스 검색

Merge pull request #105 from gmetais/basic-auth

Basic auth
Gaël Métais 9 년 전
부모
커밋
fe6a10592b
6개의 변경된 파일29개의 추가작업 그리고 9개의 파일을 삭제
  1. 3 1
      front/src/css/index.css
  2. 1 1
      front/src/js/services/apiService.js
  3. 2 1
      front/src/less/index.less
  4. 3 3
      front/src/views/index.html
  5. 19 2
      lib/tools/weightChecker/weightChecker.js
  6. 1 1
      package.json

+ 3 - 1
front/src/css/index.css

@@ -33,7 +33,8 @@
 .settings select {
   font-size: 1em;
 }
-.settings input[type=text] {
+.settings input[type=text],
+.settings input[type=password] {
   width: 100%;
   min-width: 4em;
 }
@@ -128,6 +129,7 @@
 .advanced > div > div.label {
   width: 25%;
   white-space: nowrap;
+  vertical-align: middle;
 }
 .advanced .subTable {
   display: table;

+ 1 - 1
front/src/js/services/apiService.js

@@ -14,7 +14,7 @@ apiService.factory('API', ['$location', 'Runs', 'Results', function($location, R
                 waitForSelector: settings.waitForSelector,
                 cookie: settings.cookie,
                 authUser: settings.authUser,
-                authPass: settings.authPass,
+                authPass: settings.authPass
             };
 
             if (settings.waitForSelector && settings.waitForSelector !== '') {

+ 2 - 1
front/src/less/index.less

@@ -38,7 +38,7 @@
         font-size: 1em;
     }
 
-    input[type=text] {
+    input[type=text], input[type=password] {
         width: 100%;
         min-width: 4em;
     }
@@ -147,6 +147,7 @@
             &.label {
                 width: 25%;
                 white-space: nowrap;
+                vertical-align: middle;
             }
         }
     }

+ 3 - 3
front/src/views/index.html

@@ -42,7 +42,7 @@
                 </div>
                 <div><input type="text" name="cookie" ng-model="settings.cookie" /></div>
             </div>
-            <!--<div>
+            <div>
                 <div class="label">
                     Authent
                     <span class="settingsTooltip">
@@ -57,10 +57,10 @@
                     </div>
                     <div>
                         <div><span>password</div>
-                        <div><input type="text" class="authField" name="authPass" ng-model="settings.authPass" /></div>
+                        <div><input type="password" class="authField" name="authPass" ng-model="settings.authPass" /></div>
                     </div>
                 </div>
-            </div>-->
+            </div>
             <!--<div>
                 <div class="label">Blocked domains</div>
                 <div>

+ 19 - 2
lib/tools/weightChecker/weightChecker.js

@@ -33,11 +33,19 @@ var WeightChecker = function() {
         delete data.toolsResults.phantomas.metrics.requestsList;
         delete data.toolsResults.phantomas.offenders.requestsList;
 
+        var httpAuth = null;
+        if (data.params && data.params.options && data.params.options.authUser && data.params.options.authPass) {
+            httpAuth = {
+                username: data.params.options.authUser,
+                password: data.params.options.authPass
+            };
+        }
+
         // Transform every request into a download function with a callback when done
         var redownloadList = requestsList.map(function(entry) {
             return function(callback) {
                 
-                redownloadEntry(entry)
+                redownloadEntry(entry, httpAuth)
 
                 .then(imageOptimizer.optimizeImage)
 
@@ -313,7 +321,7 @@ var WeightChecker = function() {
     }
 
 
-    function redownloadEntry(entry) {
+    function redownloadEntry(entry, httpAuth) {
         var deferred = Q.defer();
         
         function downloadError(message) {
@@ -367,6 +375,15 @@ var WeightChecker = function() {
             timeout: REQUEST_TIMEOUT
         };
 
+        // Basic auth
+        if (httpAuth) {
+            requestOptions.auth = {
+                user: httpAuth.username,
+                pass: httpAuth.password,
+                sendImmediately: false // Tries a first time without auth, wait for a 401 error before resending
+            };
+        }
+
         download(requestOptions, entry.contentType, function(error, result) {
             if (error) {
                 if (error.code === 'ETIMEDOUT') {

+ 1 - 1
package.json

@@ -38,7 +38,7 @@
     "lwip": "0.0.7",
     "meow": "3.3.0",
     "minimize": "1.7.0",
-    "phantomas": "1.11.0",
+    "phantomas": "1.12.0",
     "ps-node": "0.0.4",
     "q": "1.4.1",
     "request": "2.61.0",