Skip to content

Commit

Permalink
User attribute tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Boes committed Jul 13, 2017
1 parent e4cf99e commit c186802
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/Saml2/Saml2AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,53 @@ public function testCanGetLastError()
$this->assertSame('lastError', $saml2->getLastErrorReason());
}

public function testGetUserAttribute() {
$auth = m::mock('OneLogin_Saml2_Auth');
$saml2 = new Saml2Auth($auth);

$user = $saml2->getSaml2User();

$auth->shouldReceive('getAttribute')
->with('urn:oid:0.9.2342.19200300.100.1.3')
->andReturn(['[email protected]']);

$this->assertEquals(['[email protected]'], $user->getAttribute('urn:oid:0.9.2342.19200300.100.1.3'));
}

public function testParseSingleUserAttribute() {
$auth = m::mock('OneLogin_Saml2_Auth');
$saml2 = new Saml2Auth($auth);

$user = $saml2->getSaml2User();

$auth->shouldReceive('getAttribute')
->with('urn:oid:0.9.2342.19200300.100.1.3')
->andReturn(['[email protected]']);

$user->parseUserAttribute('urn:oid:0.9.2342.19200300.100.1.3', 'email');

$this->assertEquals($user->email, ['[email protected]']);
}

public function testParseMultipleUserAttributes() {
$auth = m::mock('OneLogin_Saml2_Auth');
$saml2 = new Saml2Auth($auth);

$user = $saml2->getSaml2User();

$auth->shouldReceive('getAttribute')
->twice()
->andReturn(['[email protected]'], ['Test User']);

$user->parseAttributes([
'email' => 'urn:oid:0.9.2342.19200300.100.1.3',
'displayName' => 'urn:oid:2.16.840.1.113730.3.1.241'
]);

$this->assertEquals($user->email, ['[email protected]']);
$this->assertEquals($user->displayName, ['Test User']);
}

/**
* Cant test here. It uses Laravel dependencies (eg. config())
*/
Expand Down

0 comments on commit c186802

Please sign in to comment.