From 85170c9570a5de17a5e251c4f44d874089cf766a Mon Sep 17 00:00:00 2001
From: webchick <webchick@24967.no-reply.drupal.org>
Date: Thu, 23 Jan 2014 22:01:55 -0800
Subject: [PATCH] Issue #2108573 by pwolanin, swentel: Password-hash.sh is
 broken.

---
 .../Drupal/system/Tests/System/ScriptTest.php | 59 +++++++++++++++++++
 core/scripts/password-hash.sh                 | 10 ++--
 2 files changed, 65 insertions(+), 4 deletions(-)
 create mode 100644 core/modules/system/lib/Drupal/system/Tests/System/ScriptTest.php

diff --git a/core/modules/system/lib/Drupal/system/Tests/System/ScriptTest.php b/core/modules/system/lib/Drupal/system/Tests/System/ScriptTest.php
new file mode 100644
index 000000000000..3069aabfe01c
--- /dev/null
+++ b/core/modules/system/lib/Drupal/system/Tests/System/ScriptTest.php
@@ -0,0 +1,59 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\system\Tests\System\ScriptTest.
+ */
+
+namespace Drupal\system\Tests\System;
+
+use Drupal\simpletest\UnitTestBase;
+
+/**
+ * Tests core shell scripts.
+ */
+class ScriptTest extends UnitTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Shell scripts',
+      'description' => 'Tests Core utility shell scripts.',
+      'group' => 'System',
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setUp() {
+    parent::setUp();
+    $path_parts = explode(DIRECTORY_SEPARATOR, __DIR__);
+    // This file is 8 levels below the Drupal root.
+    $root = implode(DIRECTORY_SEPARATOR, array_slice($path_parts, 0, -8));
+    chdir($root);
+  }
+
+  /**
+   * Tests password-hash.sh.
+   */
+  public function testPasswordHashSh() {
+    $cmd = 'core/scripts/password-hash.sh xyz';
+    exec($cmd, $output, $exit_code);
+    $this->assertIdentical(0, $exit_code, 'Exit code');
+    $this->assertTrue(strpos(implode(' ', $output), 'hash: $S$') !== FALSE);
+  }
+
+  /**
+   * Tests rebuild_token_calculator.sh.
+   */
+  public function testRebuildTokenCalculatorSh() {
+    $cmd = 'core/scripts/rebuild_token_calculator.sh';
+    exec($cmd, $output, $exit_code);
+    $this->assertIdentical(0, $exit_code, 'Exit code');
+    $this->assertTrue(strpos(implode(' ', $output), 'token=') !== FALSE);
+  }
+
+}
diff --git a/core/scripts/password-hash.sh b/core/scripts/password-hash.sh
index ad0ace6e741a..8c6ebb1c3c24 100755
--- a/core/scripts/password-hash.sh
+++ b/core/scripts/password-hash.sh
@@ -1,4 +1,4 @@
-#!/usr/bin/php
+#!/usr/bin/env php
 <?php
 
 /**
@@ -78,10 +78,12 @@
   }
 }
 
-chdir('..');
 $core = dirname(__DIR__);
-include_once $core . '/includes/password.inc';
-include_once $core . '/includes/bootstrap.inc';
+require_once $core . '/vendor/autoload.php';
+require_once $core . '/includes/bootstrap.inc';
+
+// Bootstrap the code so we have the container.
+drupal_bootstrap(DRUPAL_BOOTSTRAP_CODE);
 
 $password_hasher = \Drupal::service('password');
 
-- 
GitLab