Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions includes/class-token-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public function get( $key, $hash = true ) {
}

$value['user'] = $user_id;
$value['sub'] = $value['me'];
return $value;
}

Expand Down
1 change: 1 addition & 0 deletions tests/test-introspection-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static function wpSetUpBeforeClass( $factory ) {
);
static::$test_auth_code['me'] = get_author_posts_url( static::$author_id );
static::$test_token['me'] = get_author_posts_url( static::$author_id );
static::$test_token['sub'] = static::$test_token['me'];
static::$refresh_token['me'] = get_author_posts_url( static::$author_id );
static::$subscriber_id = $factory->user->create(
array(
Expand Down
1 change: 1 addition & 0 deletions tests/test-revocation-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static function wpSetUpBeforeClass( $factory ) {
);
static::$test_auth_code['me'] = get_author_posts_url( static::$author_id );
static::$test_token['me'] = get_author_posts_url( static::$author_id );
static::$test_token['sub'] = static::$test_token['me'];
static::$refresh_token['me'] = get_author_posts_url( static::$author_id );
static::$subscriber_id = $factory->user->create(
array(
Expand Down
1 change: 1 addition & 0 deletions tests/test-token-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public static function wpSetUpBeforeClass( $factory ) {
);
static::$test_auth_code['me'] = get_author_posts_url( static::$author_id );
static::$test_token['me'] = get_author_posts_url( static::$author_id );
static::$test_token['sub'] = static::$test_token['me'];
static::$refresh_token['me'] = get_author_posts_url( static::$author_id );
static::$subscriber_id = $factory->user->create(
array(
Expand Down
12 changes: 7 additions & 5 deletions tests/test-tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ class TokensTest extends WP_UnitTestCase {
public function test_set_and_get_user_token() {
$user_id = self::factory()->user->create();
$tokens = new Token_User( '_indieauth_code_', $user_id );
$token = array( 'foo' => 'foo', 'bar' => 'bar' );
$token = array( 'foo' => 'foo', 'bar' => 'bar', 'me' => 'https://example.com' );
$key = $tokens->set( $token );
$get = $tokens->get( $key );
unset( $get['user'] );
$token['sub'] = $token['me'];
$this->assertEquals( $token, $get );
}

public function test_find_token_users() {
$user_id_1 = self::factory()->user->create();
$user_id_2 = self::factory()->user->create();
$tokens = new Token_User( '_indieauth_code_', $user_id_1 );
$token = array( 'foo' => 'foo', 'bar' => 'bar' );
$token = array( 'foo' => 'foo', 'bar' => 'bar', 'me' => 'https://example.com' );
$tokens->set( $token );
$tokens->set_user( $user_id_2 );
$key = $tokens->set( $token );
Expand All @@ -27,7 +28,7 @@ public function test_find_by_uuid() {
$user_id_1 = self::factory()->user->create();
$tokens = new Token_User( '_indieauth_code_', $user_id_1 );
$uuid = wp_generate_uuid4();
$token = array( 'foo' => 'foo', 'bar' => 'bar', 'uuid' => $uuid );
$token = array( 'foo' => 'foo', 'bar' => 'bar', 'me' => 'https://example.com', 'uuid' => $uuid );
$access_token = $tokens->set( $token );
$return = $tokens->find_by_field( 'uuid', $uuid, $user_id_1 );
$first = reset( $return );
Expand All @@ -39,7 +40,7 @@ public function test_find_by_uuid() {
public function test_expired_token() {
$user_id = self::factory()->user->create();
$tokens = new Token_User( '_indieauth_code_', $user_id );
$token = array( 'foo' => 'foo', 'bar' => 'bar' );
$token = array( 'foo' => 'foo', 'bar' => 'bar', 'me' => 'https://example.com' );
$key = $tokens->set( $token, -30 );
$get = $tokens->get( $key );
$this->assertFalse( $get );
Expand All @@ -48,11 +49,12 @@ public function test_expired_token() {
public function test_destroy_token() {
$user_id = self::factory()->user->create();
$tokens = new Token_User( '_indieauth_code_', $user_id );
$token = array( 'foo' => 'foo', 'bar' => 'bar' );
$token = array( 'foo' => 'foo', 'bar' => 'bar', 'me' => 'https://example.com' );
$key = $tokens->set( $token, 300 );
$get = $tokens->get( $key );
unset( $get['user'] );
unset( $get['exp' ] );
$token['sub'] = $token['me'];
$this->assertEquals( $get, $token );
$destroy = $tokens->destroy( $key );
$this->assertTrue( $destroy );
Expand Down