1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Cleaned tests up, Started LDAP tests, Created LDAP wrapper

This commit is contained in:
Dan Brown
2016-01-15 23:21:47 +00:00
parent 14feef3679
commit 0821672e70
15 changed files with 259 additions and 79 deletions

View File

@ -7,7 +7,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
class ActivityTrackingTest extends TestCase
{
public function testRecentlyViewedBooks()
public function test_recently_viewed_books()
{
$books = \BookStack\Book::all()->take(10);
@ -21,7 +21,7 @@ class ActivityTrackingTest extends TestCase
->seeInElement('#recents', $books[1]->name);
}
public function testPopularBooks()
public function test_popular_books()
{
$books = \BookStack\Book::all()->take(10);

View File

@ -5,23 +5,19 @@ use BookStack\EmailConfirmation;
class AuthTest extends TestCase
{
public function testAuthWorking()
public function test_auth_working()
{
$this->visit('/')
->seePageIs('/login');
}
public function testLogin()
public function test_login()
{
$this->visit('/')
->seePageIs('/login');
$this->login('admin@admin.com', 'password')
->seePageIs('/')
->see('BookStack');
->seePageIs('/');
}
public function testPublicViewing()
public function test_public_viewing()
{
$settings = app('BookStack\Services\SettingService');
$settings->put('app-public', 'true');
@ -30,7 +26,7 @@ class AuthTest extends TestCase
->see('Sign In');
}
public function testRegistrationShowing()
public function test_registration_showing()
{
// Ensure registration form is showing
$this->setSettings(['registration-enabled' => 'true']);
@ -40,7 +36,7 @@ class AuthTest extends TestCase
->seePageIs('/register');
}
public function testNormalRegistration()
public function test_normal_registration()
{
// Set settings and get user instance
$this->setSettings(['registration-enabled' => 'true']);
@ -58,7 +54,8 @@ class AuthTest extends TestCase
->seeInDatabase('users', ['name' => $user->name, 'email' => $user->email]);
}
public function testConfirmedRegistration()
public function test_confirmed_registration()
{
// Set settings and get user instance
$this->setSettings(['registration-enabled' => 'true', 'registration-confirmation' => 'true']);
@ -102,7 +99,32 @@ class AuthTest extends TestCase
->seeInDatabase('users', ['name' => $user->name, 'email' => $user->email, 'email_confirmed' => true]);
}
public function testUserCreation()
public function test_restricted_registration()
{
$this->setSettings(['registration-enabled' => 'true', 'registration-confirmation' => 'true', 'registration-restrict' => 'example.com']);
$user = factory(\BookStack\User::class)->make();
// Go through registration process
$this->visit('/register')
->type($user->name, '#name')
->type($user->email, '#email')
->type($user->password, '#password')
->press('Create Account')
->seePageIs('/register')
->dontSeeInDatabase('users', ['email' => $user->email])
->see('That email domain does not have access to this application');
$user->email = 'barry@example.com';
$this->visit('/register')
->type($user->name, '#name')
->type($user->email, '#email')
->type($user->password, '#password')
->press('Create Account')
->seePageIs('/register/confirm')
->seeInDatabase('users', ['name' => $user->name, 'email' => $user->email, 'email_confirmed' => false]);
}
public function test_user_creation()
{
$user = factory(\BookStack\User::class)->make();
@ -120,7 +142,7 @@ class AuthTest extends TestCase
->see($user->name);
}
public function testUserUpdating()
public function test_user_updating()
{
$user = \BookStack\User::all()->last();
$password = $user->password;
@ -136,7 +158,7 @@ class AuthTest extends TestCase
->notSeeInDatabase('users', ['name' => $user->name]);
}
public function testUserPasswordUpdate()
public function test_user_password_update()
{
$user = \BookStack\User::all()->last();
$userProfilePage = '/users/' . $user->id;
@ -156,7 +178,7 @@ class AuthTest extends TestCase
$this->assertTrue(Hash::check('newpassword', $userPassword));
}
public function testUserDeletion()
public function test_user_deletion()
{
$userDetails = factory(\BookStack\User::class)->make();
$user = $this->getNewUser($userDetails->toArray());
@ -170,7 +192,7 @@ class AuthTest extends TestCase
->notSeeInDatabase('users', ['name' => $user->name]);
}
public function testUserCannotBeDeletedIfLastAdmin()
public function test_user_cannot_be_deleted_if_last_admin()
{
$adminRole = \BookStack\Role::getRole('admin');
// Ensure we currently only have 1 admin user
@ -184,7 +206,7 @@ class AuthTest extends TestCase
->see('You cannot delete the only admin');
}
public function testLogout()
public function test_logout()
{
$this->asAdmin()
->visit('/')
@ -200,7 +222,7 @@ class AuthTest extends TestCase
* @param string $password
* @return $this
*/
private function login($email, $password)
protected function login($email, $password)
{
return $this->visit('/login')
->type($email, '#email')

43
tests/Auth/LdapTest.php Normal file
View File

@ -0,0 +1,43 @@
<?php
use BookStack\Services\LdapService;
use BookStack\User;
class LdapTest extends \TestCase
{
protected $mockLdap;
protected $mockUser;
protected $resourceId = 'resource-test';
public function setUp()
{
parent::setUp();
app('config')->set(['auth.method' => 'ldap', 'services.ldap.base_dn' => 'dc=ldap,dc=local', 'auth.providers.users.driver' => 'ldap']);
$this->mockLdap = Mockery::mock(BookStack\Services\Ldap::class);
$this->app['BookStack\Services\Ldap'] = $this->mockLdap;
$this->mockUser = factory(User::class)->make();
}
public function test_ldap_login()
{
$this->mockLdap->shouldReceive('connect')->once()->andReturn($this->resourceId);
$this->mockLdap->shouldReceive('setOption')->once();
$this->mockLdap->shouldReceive('searchAndGetEntries')->twice()
->with($this->resourceId, config('services.ldap.base_dn'), Mockery::type('string'), Mockery::type('array'))
->andReturn(['count' => 1, 0 => [
'uid' => [$this->mockUser->name],
'cn' => [$this->mockUser->name],
'dn' => ['dc=test'.config('services.ldap.base_dn')]
]]);
$this->mockLdap->shouldReceive('bind')->times(1)->andReturn(true);
$this->visit('/login')
->see('Username')
->type($this->mockUser->name, '#username')
->type($this->mockUser->password, '#password')
->press('Sign In')
->seePageIs('/login')->see('Please enter an email to use for this account.');
}
}

View File

@ -3,13 +3,13 @@
class SocialAuthTest extends TestCase
{
public function testSocialRegistration()
public function test_social_registration()
{
// http://docs.mockery.io/en/latest/reference/startup_methods.html
$user = factory(\BookStack\User::class)->make();
$this->setSettings(['registration-enabled' => 'true']);
$this->setEnvironment(['GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc', 'APP_URL' => 'http://localhost']);
config(['GOOGLE_APP_ID' => 'abc123', 'GOOGLE_APP_SECRET' => '123abc', 'APP_URL' => 'http://localhost']);
$mockSocialite = Mockery::mock('Laravel\Socialite\Contracts\Factory');
$this->app['Laravel\Socialite\Contracts\Factory'] = $mockSocialite;
@ -32,11 +32,4 @@ class SocialAuthTest extends TestCase
$this->seeInDatabase('social_accounts', ['user_id' => $user->id]);
}
protected function setEnvironment($array)
{
foreach ($array as $key => $value) {
putenv("$key=$value");
}
}
}

View File

@ -5,7 +5,7 @@ use Illuminate\Support\Facades\DB;
class EntityTest extends TestCase
{
public function testEntityCreation()
public function test_entity_creation()
{
// Test Creation
@ -51,7 +51,7 @@ class EntityTest extends TestCase
return \BookStack\Book::find($book->id);
}
public function testBookSortPageShows()
public function test_book_sort_page_shows()
{
$books = \BookStack\Book::all();
$bookToSort = $books[0];
@ -65,7 +65,7 @@ class EntityTest extends TestCase
->see($books[1]->name);
}
public function testBookSortItemReturnsBookContent()
public function test_book_sort_item_returns_book_content()
{
$books = \BookStack\Book::all();
$bookToSort = $books[0];
@ -155,7 +155,7 @@ class EntityTest extends TestCase
return $book;
}
public function testPageSearch()
public function test_page_search()
{
$book = \BookStack\Book::all()->first();
$page = $book->pages->first();
@ -170,7 +170,7 @@ class EntityTest extends TestCase
->seePageIs($page->getUrl());
}
public function testInvalidPageSearch()
public function test_invalid_page_search()
{
$this->asAdmin()
->visit('/')
@ -180,7 +180,7 @@ class EntityTest extends TestCase
->seeStatusCode(200);
}
public function testEmptySearchRedirectsBack()
public function test_empty_search_redirects_back()
{
$this->asAdmin()
->visit('/')
@ -188,7 +188,7 @@ class EntityTest extends TestCase
->seePageIs('/');
}
public function testBookSearch()
public function test_book_search()
{
$book = \BookStack\Book::all()->first();
$page = $book->pages->last();
@ -202,7 +202,7 @@ class EntityTest extends TestCase
->see($chapter->name);
}
public function testEmptyBookSearchRedirectsBack()
public function test_empty_book_search_redirects_back()
{
$book = \BookStack\Book::all()->first();
$this->asAdmin()
@ -212,7 +212,7 @@ class EntityTest extends TestCase
}
public function testEntitiesViewableAfterCreatorDeletion()
public function test_entities_viewable_after_creator_deletion()
{
// Create required assets and revisions
$creator = $this->getNewUser();
@ -225,7 +225,7 @@ class EntityTest extends TestCase
$this->checkEntitiesViewable($entities);
}
public function testEntitiesViewableAfterUpdaterDeletion()
public function test_entities_viewable_after_updater_deletion()
{
// Create required assets and revisions
$creator = $this->getNewUser();

View File

@ -3,7 +3,7 @@
class PublicViewTest extends TestCase
{
public function testBooksViewable()
public function test_books_viewable()
{
$this->setSettings(['app-public' => 'true']);
$books = \BookStack\Book::orderBy('name', 'asc')->take(10)->get();
@ -13,14 +13,14 @@ class PublicViewTest extends TestCase
$this->visit('/books')
->seeStatusCode(200)
->see($books[0]->name)
// Check indavidual book page is showing and it's child contents are visible.
// Check individual book page is showing and it's child contents are visible.
->click($bookToVisit->name)
->seePageIs($bookToVisit->getUrl())
->see($bookToVisit->name)
->see($bookToVisit->chapters()->first()->name);
}
public function testChaptersViewable()
public function test_chapters_viewable()
{
$this->setSettings(['app-public' => 'true']);
$chapterToVisit = \BookStack\Chapter::first();
@ -30,7 +30,7 @@ class PublicViewTest extends TestCase
$this->visit($chapterToVisit->getUrl())
->seeStatusCode(200)
->see($chapterToVisit->name)
// Check indavidual chapter page is showing and it's child contents are visible.
// Check individual chapter page is showing and it's child contents are visible.
->see($pageToVisit->name)
->click($pageToVisit->name)
->see($chapterToVisit->book->name)