Documentation

PasswordTest extends TestCase
in package

The base of every unit test that needs more than the class under test.

A test asks for what it needs and gets it without a web server, a database or a config file:

$this->bootFramework(["rootDirectory" => "sub"]);
$request = $this->request($this->input()->withUrl("http://localhost/sub/a/b"));

Everything handed out here is taken back after the test, so no test sees the settings, the request or the cached values of another one.

Table of Contents

BELOW_COST  = ["memory_cost" => 8192, "time_cost" => 1, "threads" => 1]
ERROR_LENGTH  = "Invalid password length."
ERROR_SALT  = "A legacy or onion hash requires a salt."
LEGACY_HASH  = "772e7e18b509ee9dbf4a53d415187fa49c68c991873e3282c0025e9e53d4c946125f184c34e04a7fcd5136fcdc04bedc17afd981380ee05ccb7683e7d83ec615"
LEGACY_PW  = "password"
LEGACY_SALT  = "4401287036553e310907533.22322450"
WP_BCRYPT  = "$wp$2y$10$EvwwMyCdG7u1ShgRw5RUAOkL2TWi/XP12tEdLLuFRZNcJJe9k3GB2"
WP_PORTABLE  = "$P$BtYtOPOLRoHt8wylQ6fJWJEKhqfXiG1"
WP_PW  = "1205#demo"
$temporaryDirectories  : array<string|int, mixed>
lengthBoundaries()  : array<string|int, mixed>
missingSalts()  : array<string|int, mixed>
schemes()  : array<string|int, mixed>
testALegacyAndAnOnionHashVerifyUnderEitherScheme()  : void
testAnEmptyStoredValueIsWrongForEverySchemeAndNeedsNoSalt()  : void
testDoesNotUpgradeABelowCostHashOnAWrongPassword()  : void
testHashAppliesTheLengthBoundaries()  : void
testMatchesACurrentCostHashWithNoUpgrade()  : void
testProducesAnArgon2idHashThatVerifies()  : void
testRejectsALegacyHashWithAnotherSalt()  : void
testRejectsANativeHashOnTheLegacyPath()  : void
testRejectsAnEmptyStoredValue()  : void
testRejectsAnUnknownScheme()  : void
testRejectsAPasswordAboveTheMaximumLength()  : void
testRejectsAPasswordBelowTheMinimumLength()  : void
testRejectsAWrongPassword()  : void
testRejectsAWrongPasswordAgainstALegacyHash()  : void
testRejectsAWrongPasswordAgainstAnOnionHash()  : void
testRejectsForeignAndMalformedStoredValues()  : void
testThrowsForAPasswordLongerThanTheMaximum()  : void
testThrowsForAPasswordShorterThanTheMinimum()  : void
testThrowsWhenALegacyHashHasNoSalt()  : void
testUpgradesABelowCostHashOnACorrectLoginRehashOnLogin()  : void
testUpgradesAHashOfAnotherAlgorithmOnACorrectLogin()  : void
testVerifiesALegacyHashAndYieldsANativeUpgrade()  : void
testVerifiesAPre68PPhpassHashAndYieldsANativeUpgrade()  : void
testVerifiesAWordPress68WpBcryptHashAndYieldsANativeUpgrade()  : void
testVerifiesEmojiUmlautsCjkSpecialCharacterSpacedAndLongPasswordsInBothFormats()  : void
testVerifiesNativelyWhenNoSchemeIsGiven()  : void
testVerifyAppliesTheLengthBoundaries()  : void
testWrapsALegacyHashVerifiesItAndYieldsANativeUpgrade()  : void
testWrapsWithAReducedCost()  : void
unknownSchemes()  : array<string|int, mixed>
wordPressVectors()  : array<string|int, mixed>
assertThrows()  : Throwable
Asserts that the action throws exactly this class, no subclass of it, with exactly this message. expectException() accepts subclasses and a message that only contains the expected one.
bootFramework()  : ZubZet
Provides the framework instance the global helpers (zubzet(), config(), request(), ...) work on. It holds exactly the given settings: nothing is read from a config file, nothing connects, and there is no request, response, database or user until the test sets one.
callHidden()  : mixed
Calls a method that is not public. Only for logic that has no public way in; a test goes through the public method wherever there is one.
currentUser()  : User
Makes a user without database access the current one, the one user() returns. Its constructor would identify it through the database, so it is left out: the user is anonymous unless the test says otherwise.
inDirectory()  : mixed
Runs the action with the given directory as the working directory, for code that reads relative paths. The previous directory is restored afterwards, also when the action throws.
input()  : State
An input without any data. The with...() methods of the state fill it:
removeSetting()  : void
Removes a setting, as if its line was missing in the config file.
request()  : Request
Makes the given input the current request, the one request() returns.
requireArgon2id()  : void
Skips the test on a PHP built without Argon2. The framework hashes with PASSWORD_ARGON2ID unconditionally and composer.json does not require the support, so the tests that reach it have to tolerate its absence.
response()  : Response
Makes a new response the current one, the one response() returns.
setHiddenStatic()  : void
Sets a static property that is not public. Only for state a class keeps for the whole process and offers no way to reset.
setSettings()  : void
Changes single settings of the booted framework and keeps the others.
tearDown()  : void
temporaryDirectory()  : string
An empty directory with a trailing slash, removed after the test.
clearEndpoint()  : void
clearRuntimeCaches()  : void

Constants

BELOW_COST

private mixed BELOW_COST = ["memory_cost" => 8192, "time_cost" => 1, "threads" => 1]

ERROR_LENGTH

private mixed ERROR_LENGTH = "Invalid password length."

ERROR_SALT

private mixed ERROR_SALT = "A legacy or onion hash requires a salt."

LEGACY_HASH

private mixed LEGACY_HASH = "772e7e18b509ee9dbf4a53d415187fa49c68c991873e3282c0025e9e53d4c946125f184c34e04a7fcd5136fcdc04bedc17afd981380ee05ccb7683e7d83ec615"

LEGACY_SALT

private mixed LEGACY_SALT = "4401287036553e310907533.22322450"

WP_BCRYPT

private mixed WP_BCRYPT = "$wp$2y$10$EvwwMyCdG7u1ShgRw5RUAOkL2TWi/XP12tEdLLuFRZNcJJe9k3GB2"

WP_PORTABLE

private mixed WP_PORTABLE = "$P$BtYtOPOLRoHt8wylQ6fJWJEKhqfXiG1"

Properties

$temporaryDirectories

private array<string|int, mixed> $temporaryDirectories = []

Methods

lengthBoundaries()

public static lengthBoundaries() : array<string|int, mixed>
Return values
array<string|int, mixed> —

missingSalts()

public static missingSalts() : array<string|int, mixed>
Return values
array<string|int, mixed> —

schemes()

public static schemes() : array<string|int, mixed>
Return values
array<string|int, mixed> —

testALegacyAndAnOnionHashVerifyUnderEitherScheme()

public testALegacyAndAnOnionHashVerifyUnderEitherScheme() : void
Return values
void —

testAnEmptyStoredValueIsWrongForEverySchemeAndNeedsNoSalt()

public testAnEmptyStoredValueIsWrongForEverySchemeAndNeedsNoSalt(string $scheme) : void
Parameters
$scheme : string
Tags
dataProvider

schemes

Return values
void —

testDoesNotUpgradeABelowCostHashOnAWrongPassword()

public testDoesNotUpgradeABelowCostHashOnAWrongPassword() : void
Return values
void —

testHashAppliesTheLengthBoundaries()

public testHashAppliesTheLengthBoundaries(string $password, bool $accepted) : void
Parameters
$password : string
$accepted : bool
Tags
dataProvider

lengthBoundaries

Return values
void —

testMatchesACurrentCostHashWithNoUpgrade()

public testMatchesACurrentCostHashWithNoUpgrade() : void
Return values
void —

testProducesAnArgon2idHashThatVerifies()

public testProducesAnArgon2idHashThatVerifies() : void
Return values
void —

testRejectsALegacyHashWithAnotherSalt()

public testRejectsALegacyHashWithAnotherSalt() : void
Return values
void —

testRejectsANativeHashOnTheLegacyPath()

public testRejectsANativeHashOnTheLegacyPath() : void
Return values
void —

testRejectsAnEmptyStoredValue()

public testRejectsAnEmptyStoredValue() : void
Return values
void —

testRejectsAnUnknownScheme()

public testRejectsAnUnknownScheme(string|null $scheme) : void
Parameters
$scheme : string|null
Tags
dataProvider

unknownSchemes

Return values
void —

testRejectsAPasswordAboveTheMaximumLength()

public testRejectsAPasswordAboveTheMaximumLength() : void
Return values
void —

testRejectsAPasswordBelowTheMinimumLength()

public testRejectsAPasswordBelowTheMinimumLength() : void
Return values
void —

testRejectsAWrongPassword()

public testRejectsAWrongPassword() : void
Return values
void —

testRejectsAWrongPasswordAgainstALegacyHash()

public testRejectsAWrongPasswordAgainstALegacyHash() : void
Return values
void —

testRejectsAWrongPasswordAgainstAnOnionHash()

public testRejectsAWrongPasswordAgainstAnOnionHash() : void
Return values
void —

testRejectsForeignAndMalformedStoredValues()

public testRejectsForeignAndMalformedStoredValues() : void
Return values
void —

testThrowsForAPasswordLongerThanTheMaximum()

public testThrowsForAPasswordLongerThanTheMaximum() : void
Return values
void —

testThrowsForAPasswordShorterThanTheMinimum()

public testThrowsForAPasswordShorterThanTheMinimum() : void
Return values
void —

testThrowsWhenALegacyHashHasNoSalt()

public testThrowsWhenALegacyHashHasNoSalt(string $scheme, string|null $salt) : void
Parameters
$scheme : string
$salt : string|null
Tags
dataProvider

missingSalts

Return values
void —

testUpgradesABelowCostHashOnACorrectLoginRehashOnLogin()

public testUpgradesABelowCostHashOnACorrectLoginRehashOnLogin() : void
Return values
void —

testUpgradesAHashOfAnotherAlgorithmOnACorrectLogin()

public testUpgradesAHashOfAnotherAlgorithmOnACorrectLogin() : void
Return values
void —

testVerifiesALegacyHashAndYieldsANativeUpgrade()

public testVerifiesALegacyHashAndYieldsANativeUpgrade() : void
Return values
void —

testVerifiesAPre68PPhpassHashAndYieldsANativeUpgrade()

public testVerifiesAPre68PPhpassHashAndYieldsANativeUpgrade() : void
Return values
void —

testVerifiesAWordPress68WpBcryptHashAndYieldsANativeUpgrade()

public testVerifiesAWordPress68WpBcryptHashAndYieldsANativeUpgrade() : void
Return values
void —

testVerifiesEmojiUmlautsCjkSpecialCharacterSpacedAndLongPasswordsInBothFormats()

public testVerifiesEmojiUmlautsCjkSpecialCharacterSpacedAndLongPasswordsInBothFormats(string $password, string $bcrypt, string $portable) : void
Parameters
$password : string
$bcrypt : string
$portable : string
Tags
dataProvider

wordPressVectors

Return values
void —

testVerifiesNativelyWhenNoSchemeIsGiven()

public testVerifiesNativelyWhenNoSchemeIsGiven() : void
Return values
void —

testVerifyAppliesTheLengthBoundaries()

public testVerifyAppliesTheLengthBoundaries(string $password, bool $accepted) : void
Parameters
$password : string
$accepted : bool
Tags
dataProvider

lengthBoundaries

Return values
void —

testWrapsALegacyHashVerifiesItAndYieldsANativeUpgrade()

public testWrapsALegacyHashVerifiesItAndYieldsANativeUpgrade() : void
Return values
void —

testWrapsWithAReducedCost()

public testWrapsWithAReducedCost() : void
Return values
void —

unknownSchemes()

public static unknownSchemes() : array<string|int, mixed>
Return values
array<string|int, mixed> —

wordPressVectors()

public static wordPressVectors() : array<string|int, mixed>
Return values
array<string|int, mixed> —

assertThrows()

Asserts that the action throws exactly this class, no subclass of it, with exactly this message. expectException() accepts subclasses and a message that only contains the expected one.

protected assertThrows(class-string<\Throwable> $class, string $message, callable $action) : Throwable
Parameters
$class : class-string<\Throwable>
$message : string
$action : callable
Return values
Throwable —

bootFramework()

Provides the framework instance the global helpers (zubzet(), config(), request(), ...) work on. It holds exactly the given settings: nothing is read from a config file, nothing connects, and there is no request, response, database or user until the test sets one.

protected bootFramework([array<string, mixed> $settings = [] ]) : ZubZet
Parameters
$settings : array<string, mixed> = []

What config() returns

Return values
ZubZet —

callHidden()

Calls a method that is not public. Only for logic that has no public way in; a test goes through the public method wherever there is one.

protected callHidden(object|class-string $target, string $method, mixed ...$arguments) : mixed
Parameters
$target : object|class-string

An object, or a class name for a static method

$method : string
$arguments : mixed
Return values
mixed —

currentUser()

Makes a user without database access the current one, the one user() returns. Its constructor would identify it through the database, so it is left out: the user is anonymous unless the test says otherwise.

protected currentUser([bool $loggedIn = false ]) : User
Parameters
$loggedIn : bool = false
Return values
User —

inDirectory()

Runs the action with the given directory as the working directory, for code that reads relative paths. The previous directory is restored afterwards, also when the action throws.

protected inDirectory(string $directory, callable $action) : mixed
Parameters
$directory : string
$action : callable
Return values
mixed —

input()

An input without any data. The with...() methods of the state fill it:

protected input([string $requestOrder = "GPC" ]) : State

$this->input()->withMethod("POST")->withPost(["name" => "value"])

REQUEST is put together from GET, POST and COOKIE in the given order, whatever the php.ini of the machine says, so a test sees the same REQUEST everywhere.

Parameters
$requestOrder : string = "GPC"
Return values
State —

removeSetting()

Removes a setting, as if its line was missing in the config file.

protected removeSetting(string $key) : void
Parameters
$key : string
Return values
void —

request()

Makes the given input the current request, the one request() returns.

protected request([State|null $input = null ]) : Request

Boots the framework without settings when the test has not done so.

Parameters
$input : State|null = null
Return values
Request —

requireArgon2id()

Skips the test on a PHP built without Argon2. The framework hashes with PASSWORD_ARGON2ID unconditionally and composer.json does not require the support, so the tests that reach it have to tolerate its absence.

protected requireArgon2id() : void
Return values
void —

response()

Makes a new response the current one, the one response() returns.

protected response() : Response

Boots the framework without settings when the test has not done so.

Return values
Response —

setHiddenStatic()

Sets a static property that is not public. Only for state a class keeps for the whole process and offers no way to reset.

protected setHiddenStatic(class-string $class, string $property, mixed $value) : void
Parameters
$class : class-string
$property : string
$value : mixed
Return values
void —

setSettings()

Changes single settings of the booted framework and keeps the others.

protected setSettings(array<string, mixed> $settings) : void
Parameters
$settings : array<string, mixed>
Return values
void —

tearDown()

protected tearDown() : void
Return values
void —

temporaryDirectory()

An empty directory with a trailing slash, removed after the test.

protected temporaryDirectory() : string
Return values
string —

clearEndpoint()

private clearEndpoint() : void
Return values
void —

clearRuntimeCaches()

private clearRuntimeCaches() : void
Return values
void —

Search results