Skip to content

Commit 9e51c36

Browse files
author
Greg Bowler
committed
Pass first test ensuring authUri is always HTTPS
1 parent b13206f commit 9e51c36

File tree

4 files changed

+52
-2
lines changed

4 files changed

+52
-2
lines changed

src/Authenticator.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
<?php
22
namespace Authwave;
33

4+
use Gt\Http\Uri;
5+
use Psr\Http\Message\UriInterface;
6+
47
class Authenticator {
8+
private Cipher $cipher;
9+
private string $hostname;
10+
11+
public function __construct(Token $token, string $hostname) {
12+
$this->cipher = $token->generateCipher();
13+
$this->hostname = $hostname;
14+
}
515

16+
public function getAuthUri():UriInterface {
17+
return (new Uri())
18+
->withScheme("https")
19+
->withHost($this->hostname);
20+
}
621
}

src/Cipher.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace Authwave;
3+
4+
class Cipher {
5+
6+
}

src/Token.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
namespace Authwave;
3+
4+
class Token {
5+
private string $key;
6+
private string $tokenValue;
7+
8+
public function __construct(string $key) {
9+
$this->key = $key;
10+
$this->tokenValue = random_bytes(16);
11+
}
12+
13+
public function generateCipher():Cipher {
14+
15+
}
16+
}

test/phpunit/AuthenticatorTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
<?php
22
namespace Authwave\Test;
33

4+
use Authwave\Authenticator;
5+
use Authwave\Cipher;
6+
use Authwave\Token;
47
use PHPUnit\Framework\TestCase;
58

69
class AuthenticatorTest extends TestCase {
7-
public function testOnePlusOne() {
8-
self::assertEquals(2, 1 + 1);
10+
public function testGetAuthUriHostname() {
11+
$cipher = self::createMock(Cipher::class);
12+
$token = self::createMock(Token::class);
13+
$token->method("generateCipher")
14+
->willReturn($cipher);
15+
16+
$sut = new Authenticator($token, "example.com");
17+
$authUri = $sut->getAuthUri();
18+
self::assertStringStartsWith(
19+
"https://example.com",
20+
$authUri
21+
);
922
}
1023
}

0 commit comments

Comments
 (0)