Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/user_saml.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2017-08-04 13:54:59 +0300
committerLukas Reschke <lukas@statuscode.ch>2017-08-04 13:54:59 +0300
commitbc98b466bd7c660589c2aa7cf6df2e0be53ccfae (patch)
tree491224c5a3fad40d3ff1dff33b24465e2ba37746 /tests
parent442fa2b7098e27186a0962afe2d7a47ef7b290f3 (diff)
Set last login after successful login operation
Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/features/Shibboleth.feature3
-rw-r--r--tests/integration/features/bootstrap/FeatureContext.php22
-rw-r--r--tests/unit/UserBackendTest.php116
3 files changed, 133 insertions, 8 deletions
diff --git a/tests/integration/features/Shibboleth.feature b/tests/integration/features/Shibboleth.feature
index 94a7990e..ba543bc4 100644
--- a/tests/integration/features/Shibboleth.feature
+++ b/tests/integration/features/Shibboleth.feature
@@ -19,6 +19,7 @@ Feature: Shibboleth
And The response should be a SAML redirect page that gets submitted
And I should be redirected to "http://localhost/index.php/apps/files/"
And The user value "id" should be "student1"
+ And The last login timestamp of "student1" should not be empty
Scenario: Authenticating using Shibboleth with SAML and check if user exists on backend and not existing user
Given The setting "type" is set to "saml"
@@ -64,6 +65,7 @@ Feature: Shibboleth
Then The user value "id" should be "student1"
Then The user value "email" should be ""
And The user value "display-name" should be "Default displayname of student1"
+ And The last login timestamp of "student1" should not be empty
Scenario: Authenticating using Shibboleth with SAML in provisioning mode and custom mapped attributes
Given The setting "type" is set to "saml"
@@ -88,3 +90,4 @@ Feature: Shibboleth
And The user value "id" should be "student1"
And The user value "email" should be "student1@idptestbed.edu"
And The user value "display-name" should be "Stud Ent"
+ And The last login timestamp of "student1" should not be empty
diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php
index fb0ff724..432803e9 100644
--- a/tests/integration/features/bootstrap/FeatureContext.php
+++ b/tests/integration/features/bootstrap/FeatureContext.php
@@ -234,6 +234,28 @@ class FeatureContext implements Context {
}
/**
+ * @Then The last login timestamp of :uid should not be empty
+ *
+ * @param string $uid
+ * @throws UnexpectedValueException
+ */
+ public function theLastLoginTimestampOfShouldNotBeEmpty($uid) {
+ $response = shell_exec(
+ sprintf(
+ 'sudo -u apache OC_PASS=password /opt/rh/rh-php56/root/usr/bin/php %s user:lastseen %s',
+ __DIR__ . '/../../../../../../occ',
+ $uid
+ )
+ );
+
+ $response = trim($response);
+ $expectedStringStart = "$uid`s last login: ";
+ if(substr($response, 0, strlen($expectedStringStart)) !== $expectedStringStart) {
+ throw new UnexpectedValueException("Expected last login message, found instead '$response'");
+ }
+ }
+
+ /**
* @Given The environment variable :key is set to :value
*/
public function theEnvironmentVariableIsSetTo($key, $value) {
diff --git a/tests/unit/UserBackendTest.php b/tests/unit/UserBackendTest.php
index 5967f4a4..8946251b 100644
--- a/tests/unit/UserBackendTest.php
+++ b/tests/unit/UserBackendTest.php
@@ -26,6 +26,7 @@ use OCP\IConfig;
use OCP\IDBConnection;
use OCP\ISession;
use OCP\IURLGenerator;
+use OCP\IUser;
use OCP\IUserBackend;
use OCP\IUserManager;
use Test\TestCase;
@@ -41,7 +42,7 @@ class UserBackendTest extends TestCase {
private $db;
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
private $userManager;
- /** @var IUserBackend */
+ /** @var UserBackend|\PHPUnit_Framework_MockObject_MockObject */
private $userBackend;
public function setUp() {
@@ -52,17 +53,116 @@ class UserBackendTest extends TestCase {
$this->session = $this->createMock(ISession::class);
$this->db = $this->createMock(IDBConnection::class);
$this->userManager = $this->createMock(IUserManager::class);
+ }
- $this->userBackend = new UserBackend(
- $this->config,
- $this->urlGenerator,
- $this->session,
- $this->db,
- $this->userManager
- );
+ public function getMockedBuilder(array $mockedFunctions = []) {
+ if($mockedFunctions !== []) {
+ $this->userBackend = $this->getMockBuilder(UserBackend::class)
+ ->setConstructorArgs([
+ $this->config,
+ $this->urlGenerator,
+ $this->session,
+ $this->db,
+ $this->userManager
+ ])
+ ->setMethods($mockedFunctions)
+ ->getMock();
+ } else {
+ $this->userBackend = new UserBackend(
+ $this->config,
+ $this->urlGenerator,
+ $this->session,
+ $this->db,
+ $this->userManager
+ );
+ }
}
public function testGetBackendName() {
+ $this->getMockedBuilder();
$this->assertSame('user_saml', $this->userBackend->getBackendName());
}
+
+ public function testUpdateAttributesWithoutAttributes() {
+ $this->getMockedBuilder(['getDisplayName']);
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
+ $user = $this->createMock(IUser::class);
+
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('ExistingUser')
+ ->willReturn($user);
+ $user
+ ->expects($this->once())
+ ->method('updateLastLoginTimestamp');
+ $user
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->willReturn(null);
+ $user
+ ->expects($this->never())
+ ->method('setEMailAddress');
+ $this->userBackend
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->with('ExistingUser')
+ ->willReturn('');
+ $this->userBackend->updateAttributes('ExistingUser', []);
+ }
+
+ public function testUpdateAttributesWithoutValidUser() {
+ $this->getMockedBuilder();
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('ExistingUser')
+ ->willReturn(null);
+ $this->userBackend->updateAttributes('ExistingUser', []);
+ }
+
+ public function testUpdateAttributes() {
+ $this->getMockedBuilder(['getDisplayName', 'setDisplayName']);
+ /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */
+ $user = $this->createMock(IUser::class);
+
+ $this->config
+ ->expects($this->at(0))
+ ->method('getAppValue')
+ ->with('user_saml', 'saml-attribute-mapping-email_mapping', '')
+ ->willReturn('email');
+ $this->config
+ ->expects($this->at(1))
+ ->method('getAppValue')
+ ->with('user_saml', 'saml-attribute-mapping-displayName_mapping', '')
+ ->willReturn('displayname');
+
+
+ $this->userManager
+ ->expects($this->once())
+ ->method('get')
+ ->with('ExistingUser')
+ ->willReturn($user);
+ $user
+ ->expects($this->once())
+ ->method('updateLastLoginTimestamp');
+ $user
+ ->expects($this->once())
+ ->method('getEMailAddress')
+ ->willReturn('old@example.com');
+ $user
+ ->expects($this->once())
+ ->method('setEMailAddress')
+ ->with('new@example.com');
+ $this->userBackend
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->with('ExistingUser')
+ ->willReturn('');
+ $this->userBackend
+ ->expects($this->once())
+ ->method('setDisplayName')
+ ->with('ExistingUser', 'New Displayname');
+ $this->userBackend->updateAttributes('ExistingUser', ['email' => 'new@example.com', 'displayname' => 'New Displayname']);
+ }
}