Compare commits
1 Commits
7ca3bf56db
...
10e657364c
Author | SHA1 | Date | |
---|---|---|---|
10e657364c |
43
.env.testing
43
.env.testing
@ -1,17 +1,50 @@
|
|||||||
APP_NAME=Laravel
|
APP_NAME=Laravel
|
||||||
APP_ENV=local
|
APP_ENV=dev
|
||||||
APP_KEY=
|
APP_KEY=base64:KvIecx8zoy6RjcbJM8s98ZKs9IDGUHFVqBRn3Awfmso=
|
||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
|
|
||||||
LOG_CHANNEL=stderr
|
LOG_CHANNEL=stack
|
||||||
|
|
||||||
CACHE_DRIVER=array
|
DB_CONNECTION=mysql
|
||||||
|
DB_HOST=127.0.0.1
|
||||||
|
DB_PORT=3306
|
||||||
|
DB_DATABASE=homestead
|
||||||
|
DB_USERNAME=homestead
|
||||||
|
DB_PASSWORD=secret
|
||||||
|
|
||||||
|
BROADCAST_DRIVER=log
|
||||||
|
CACHE_DRIVER=file
|
||||||
QUEUE_CONNECTION=sync
|
QUEUE_CONNECTION=sync
|
||||||
SESSION_DRIVER=file
|
SESSION_DRIVER=file
|
||||||
SESSION_LIFETIME=120
|
SESSION_LIFETIME=120
|
||||||
|
|
||||||
LDAP_HOST=openldap
|
REDIS_HOST=127.0.0.1
|
||||||
|
REDIS_PASSWORD=null
|
||||||
|
REDIS_PORT=6379
|
||||||
|
|
||||||
|
MAIL_DRIVER=smtp
|
||||||
|
MAIL_HOST=smtp.mailtrap.io
|
||||||
|
MAIL_PORT=2525
|
||||||
|
MAIL_USERNAME=null
|
||||||
|
MAIL_PASSWORD=null
|
||||||
|
MAIL_ENCRYPTION=null
|
||||||
|
|
||||||
|
AWS_ACCESS_KEY_ID=
|
||||||
|
AWS_SECRET_ACCESS_KEY=
|
||||||
|
AWS_DEFAULT_REGION=us-east-1
|
||||||
|
AWS_BUCKET=
|
||||||
|
|
||||||
|
PUSHER_APP_ID=
|
||||||
|
PUSHER_APP_KEY=
|
||||||
|
PUSHER_APP_SECRET=
|
||||||
|
PUSHER_APP_CLUSTER=mt1
|
||||||
|
|
||||||
|
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||||
|
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||||
|
|
||||||
|
LDAP_HOST=test_ldap
|
||||||
|
LDAP_PORT=389
|
||||||
LDAP_BASE_DN="dc=Test"
|
LDAP_BASE_DN="dc=Test"
|
||||||
LDAP_USERNAME="cn=admin,dc=Test"
|
LDAP_USERNAME="cn=admin,dc=Test"
|
||||||
LDAP_PASSWORD="test"
|
LDAP_PASSWORD="test"
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
namespace App\Classes\LDAP;
|
namespace App\Classes\LDAP;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use LdapRecord\LdapRecordException;
|
use LdapRecord\LdapRecordException;
|
||||||
|
|
||||||
use App\Exceptions\Import\GeneralException;
|
use App\Exceptions\Import\GeneralException;
|
||||||
@ -17,8 +16,6 @@ use App\Ldap\Entry;
|
|||||||
*/
|
*/
|
||||||
abstract class Import
|
abstract class Import
|
||||||
{
|
{
|
||||||
private const LOGKEY = 'aI-';
|
|
||||||
|
|
||||||
// Valid LDIF commands
|
// Valid LDIF commands
|
||||||
protected const LDAP_IMPORT_ADD = 1;
|
protected const LDAP_IMPORT_ADD = 1;
|
||||||
protected const LDAP_IMPORT_DELETE = 2;
|
protected const LDAP_IMPORT_DELETE = 2;
|
||||||
@ -60,8 +57,6 @@ abstract class Import
|
|||||||
$o->save();
|
$o->save();
|
||||||
|
|
||||||
} catch (LdapRecordException $e) {
|
} catch (LdapRecordException $e) {
|
||||||
Log::error(sprintf('%s:Import Commit Error',self::LOGKEY),['e'=>$e->getMessage(),'detailed'=>$e->getDetailedError()]);
|
|
||||||
|
|
||||||
if ($e->getDetailedError())
|
if ($e->getDetailedError())
|
||||||
return collect([
|
return collect([
|
||||||
'dn'=>$o->getDN(),
|
'dn'=>$o->getDN(),
|
||||||
@ -81,8 +76,6 @@ abstract class Import
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug(sprintf('%s:Import Commited',self::LOGKEY));
|
|
||||||
|
|
||||||
return collect(['dn'=>$o->getDN(),'result'=>__('Created')]);
|
return collect(['dn'=>$o->getDN(),'result'=>__('Created')]);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -48,7 +48,7 @@ class LDIF extends Import
|
|||||||
// Add the last attribute;
|
// Add the last attribute;
|
||||||
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value);
|
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value);
|
||||||
|
|
||||||
Log::debug(sprintf('%s:- Committing Entry [%s]',self::LOGKEY,$o->getDN()));
|
Log::debug(sprintf('%s: Committing Entry [%s]',self::LOGKEY,$o->getDN()));
|
||||||
|
|
||||||
// Commit
|
// Commit
|
||||||
$result->push($this->commit($o,$action));
|
$result->push($this->commit($o,$action));
|
||||||
@ -95,7 +95,7 @@ class LDIF extends Import
|
|||||||
// If $m is NULL, then this is the 2nd (or more) line of a base64 encoded value
|
// If $m is NULL, then this is the 2nd (or more) line of a base64 encoded value
|
||||||
if (! $m) {
|
if (! $m) {
|
||||||
$value .= $line;
|
$value .= $line;
|
||||||
Log::debug(sprintf('%s:- Attribute [%s] adding [%s] (%d)',self::LOGKEY,$attribute,$line,$c));
|
Log::debug(sprintf('%s: Attribute [%s] adding [%s] (%d)',self::LOGKEY,$attribute,$line,$c));
|
||||||
|
|
||||||
// add to last attr value
|
// add to last attr value
|
||||||
continue 2;
|
continue 2;
|
||||||
@ -134,7 +134,7 @@ class LDIF extends Import
|
|||||||
$attribute = $m[1];
|
$attribute = $m[1];
|
||||||
$value = $m[3];
|
$value = $m[3];
|
||||||
|
|
||||||
Log::debug(sprintf('%s:- New Attribute [%s] with [%s] (%d)',self::LOGKEY,$attribute,$value,$c));
|
Log::debug(sprintf('%s: New Attribute [%s] with [%s] (%d)',self::LOGKEY,$attribute,$value,$c));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($version !== 1)
|
if ($version !== 1)
|
||||||
@ -146,7 +146,7 @@ class LDIF extends Import
|
|||||||
// Add the last attribute;
|
// Add the last attribute;
|
||||||
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value);
|
$o->addAttributeItem($attribute,$base64encoded ? base64_decode($value) : $value);
|
||||||
|
|
||||||
Log::debug(sprintf('%s:- Committing Entry [%s]',self::LOGKEY,$o->getDN()));
|
Log::debug(sprintf('%s: Committing Entry [%s]',self::LOGKEY,$o->getDN()));
|
||||||
|
|
||||||
// Commit
|
// Commit
|
||||||
$result->push($this->commit($o,$action));
|
$result->push($this->commit($o,$action));
|
||||||
|
@ -204,7 +204,7 @@ final class Server
|
|||||||
default => TRUE,
|
default => TRUE,
|
||||||
};
|
};
|
||||||
|
|
||||||
Log::debug(sprintf('%s:%s - %s',self::LOGKEY,$cache ? 'DN CACHEABLE' : 'DN NOT cacheable',$dn));
|
Log::debug(sprintf('%s:%s - %s',self::LOGKEY,$cache ? 'Caching' : 'Not Cached',$dn));
|
||||||
return $cache;
|
return $cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ final class Server
|
|||||||
private static function cachetime(): Carbon
|
private static function cachetime(): Carbon
|
||||||
{
|
{
|
||||||
return Carbon::now()
|
return Carbon::now()
|
||||||
->addSeconds(Config::get('ldap.cache.time') ?: 0);
|
->addSeconds(Config::get('ldap.cache.time'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -232,8 +232,7 @@ final class Server
|
|||||||
->setDN($dn)
|
->setDN($dn)
|
||||||
->cache(
|
->cache(
|
||||||
until: self::cachetime(),
|
until: self::cachetime(),
|
||||||
flush: self::cacheflush($dn)
|
flush: self::cacheflush($dn))
|
||||||
)
|
|
||||||
->select($attrs);
|
->select($attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ use Illuminate\Support\Collection;
|
|||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Crypt;
|
use Illuminate\Support\Facades\Crypt;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
use Illuminate\Support\Facades\Redirect;
|
use Illuminate\Support\Facades\Redirect;
|
||||||
use LdapRecord\Exceptions\InsufficientAccessException;
|
use LdapRecord\Exceptions\InsufficientAccessException;
|
||||||
use LdapRecord\LdapRecordException;
|
use LdapRecord\LdapRecordException;
|
||||||
@ -436,7 +435,6 @@ class HomeController extends Controller
|
|||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'ldif':
|
case 'ldif':
|
||||||
$import = new LDIFImport($x=($request->text ?: $request->file->get()));
|
$import = new LDIFImport($x=($request->text ?: $request->file->get()));
|
||||||
Log::debug('Processing LDIF import',['data'=>$x,'import'=>$import]);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -6,6 +6,7 @@ use Illuminate\Support\Collection;
|
|||||||
use Illuminate\Support\Facades\Crypt;
|
use Illuminate\Support\Facades\Crypt;
|
||||||
use LdapRecord\Support\Arr;
|
use LdapRecord\Support\Arr;
|
||||||
use LdapRecord\Models\Model;
|
use LdapRecord\Models\Model;
|
||||||
|
use LdapRecord\Query\Model\Builder;
|
||||||
|
|
||||||
use App\Classes\LDAP\Attribute;
|
use App\Classes\LDAP\Attribute;
|
||||||
use App\Classes\LDAP\Attribute\Factory;
|
use App\Classes\LDAP\Attribute\Factory;
|
||||||
|
@ -17,10 +17,7 @@ class LoginObjectclassRule implements Rule
|
|||||||
public function passes(LdapRecord $user,?Eloquent $model=NULL): bool
|
public function passes(LdapRecord $user,?Eloquent $model=NULL): bool
|
||||||
{
|
{
|
||||||
if ($x=config('pla.login.objectclass')) {
|
if ($x=config('pla.login.objectclass')) {
|
||||||
return count(array_intersect(
|
return count(array_intersect($user->objectclass,$x));
|
||||||
array_map('strtolower',$user?->objectclass ?: []),
|
|
||||||
array_map('strtolower',$x)
|
|
||||||
));
|
|
||||||
|
|
||||||
// Otherwise allow the user to login
|
// Otherwise allow the user to login
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,242 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature;
|
|
||||||
|
|
||||||
use App\Classes\LDAP\Attribute;
|
|
||||||
use App\Ldap\Entry;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This unit will test Attributes that are:
|
|
||||||
* + no_attr_tag attributes vs those with attr_tags, AND
|
|
||||||
* + md5 attributes vs those that are not md5 attributes
|
|
||||||
*
|
|
||||||
* objectClass (a no_attr_tags_attribute)
|
|
||||||
* userPassword (a no_attr_tags_attribute, and an md5 attribute)
|
|
||||||
* certificate (a no_attr_tags attribute)
|
|
||||||
* [internal attribute] (which is a no_attr_tags attribute)
|
|
||||||
* mail (a normal attribute)
|
|
||||||
*
|
|
||||||
* => no_lang_tag attributes
|
|
||||||
* + ->values returns a Collection of values
|
|
||||||
* + ->values_old return a Collection of old values
|
|
||||||
* + ->tagValues() returns a Collection of values
|
|
||||||
* + ->tagValuesOld() return a Collection of old values
|
|
||||||
* + ->render_old_item() should be the raw value (unless an md5attribute, then the md5 value)
|
|
||||||
* + ->render_new_item() should be the raw value (unless an md5attribute, then the md5 value)
|
|
||||||
* + ->_values is array with only 1 key _null_ with an array of values
|
|
||||||
* + ->_values_old is array with only 1 key _null_ with an array of values
|
|
||||||
* + ->isDirty processing when there is a new value in the _null_ key and in another key (it should be ignored for no_attr_tags attributes)
|
|
||||||
* + ->isDirty processing when there is a new value, and its an md5 attribute
|
|
||||||
*
|
|
||||||
* The goal here is that
|
|
||||||
* + no_attr_tags attributes return an array of values not indexed by an attr_tag
|
|
||||||
* + attr_tag attributes are an array of values indexed by an attr_tag
|
|
||||||
* + md5 attributes will render the md5 value, and compare the md5 value when determining if it has changed
|
|
||||||
*
|
|
||||||
* This will mean that our views then can render attributes with tagValues() and render_xxx_item() without just by calling
|
|
||||||
* those methods with the langtag for the attribute rendering
|
|
||||||
*
|
|
||||||
* Attributes that are no_attr_tag attributes should not render anything in non-default langtag views
|
|
||||||
*/
|
|
||||||
class AttributeTagsTest extends TestCase
|
|
||||||
{
|
|
||||||
private function read()
|
|
||||||
{
|
|
||||||
static $o = NULL;
|
|
||||||
|
|
||||||
if (is_null($o)) {
|
|
||||||
$dn = 'cn=Bart Simpson,ou=People,o=Simpsons';
|
|
||||||
$this->assertTrue($this->login());
|
|
||||||
$this->assertEquals($dn,$o=config('server')->fetch($dn));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $o;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_uid()
|
|
||||||
{
|
|
||||||
// Test UID, which can have attribute tags
|
|
||||||
$o = $this->read();
|
|
||||||
$new = ['newbart'];
|
|
||||||
$o->uid = [
|
|
||||||
'_null_' => $new,
|
|
||||||
];
|
|
||||||
|
|
||||||
$oo = $o->getObject('uid');
|
|
||||||
|
|
||||||
$this->assertInstanceOf(Attribute::class,$oo);
|
|
||||||
|
|
||||||
// ->values returns a Collection of values
|
|
||||||
// ->_values is array with only 1 key _null_ with an array of values
|
|
||||||
$this->assertCount(1,$oo->values);
|
|
||||||
$this->assertArrayHasKey(Entry::TAG_NOTAG,$oo->values);
|
|
||||||
$this->assertCount(1,$oo->values[Entry::TAG_NOTAG]);
|
|
||||||
|
|
||||||
// ->values_old return a Collection of old values
|
|
||||||
// ->_values_old is array with only 1 key _null_ with an array of values
|
|
||||||
$this->assertCount(1,$oo->values_old);
|
|
||||||
$this->assertArrayHasKey(Entry::TAG_NOTAG,$oo->values_old);
|
|
||||||
$this->assertCount(1,$oo->values_old[Entry::TAG_NOTAG]);
|
|
||||||
|
|
||||||
// ->tagValues() returns a Collection of values
|
|
||||||
$this->assertCount(1,$oo->tagValues());
|
|
||||||
|
|
||||||
// ->tagValuesOld() return a Collection of old values
|
|
||||||
$this->assertCount(1,$oo->tagValuesOld());
|
|
||||||
|
|
||||||
// ->render_item_old() should be the raw value (unless an md5attribute, then the md5 value)
|
|
||||||
$this->assertEquals('bart',$oo->render_item_old(Entry::TAG_NOTAG.'.0'));
|
|
||||||
// ->render_item_new() should be the raw value (unless an md5attribute, then the md5 value)
|
|
||||||
$this->assertEquals('newbart',$oo->render_item_new(Entry::TAG_NOTAG.'.0'));
|
|
||||||
|
|
||||||
// ->isDirty processing when there is a new value in the _null_ key and in another key (it should be ignored for no_attr_tags attributes)
|
|
||||||
// ->isDirty processing when there is a new value, and its an md5 attribute
|
|
||||||
$this->assertTrue($oo->isDirty());
|
|
||||||
$this->assertCount(1,$x=$o->getDirty());
|
|
||||||
$this->assertArrayHasKey('uid',$x);
|
|
||||||
$this->assertCount(1,$x['uid']);
|
|
||||||
$this->assertEquals($new,$x['uid']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_objectclass()
|
|
||||||
{
|
|
||||||
// Test ObjectClass, which can NOT have attribute tags
|
|
||||||
$o = $this->read();
|
|
||||||
$newoc = [
|
|
||||||
'inetOrgPerson',
|
|
||||||
'posixAccount',
|
|
||||||
'top',
|
|
||||||
'shadowAccount',
|
|
||||||
'inetLocalMailRecipient',
|
|
||||||
];
|
|
||||||
|
|
||||||
$o->objectclass = [
|
|
||||||
'_null_' => $newoc,
|
|
||||||
];
|
|
||||||
|
|
||||||
$oo = $o->getObject('objectclass');
|
|
||||||
|
|
||||||
$this->assertInstanceOf(Attribute\ObjectClass::class,$oo);
|
|
||||||
$this->assertTrue($oo->no_attr_tags);
|
|
||||||
|
|
||||||
// ->values returns a Collection of values
|
|
||||||
// ->_values is array with only 1 key _null_ with an array of values
|
|
||||||
$this->assertCount(5,$oo->values);
|
|
||||||
$this->assertArrayNotHasKey(Entry::TAG_NOTAG,$oo->values);
|
|
||||||
|
|
||||||
// ->values_old return a Collection of old values
|
|
||||||
// ->_values_old is array with only 1 key _null_ with an array of values
|
|
||||||
$this->assertCount(4,$oo->values_old);
|
|
||||||
$this->assertArrayNotHasKey(Entry::TAG_NOTAG,$oo->values_old);
|
|
||||||
|
|
||||||
// ->tagValues() returns a Collection of values
|
|
||||||
$this->assertCount(5,$oo->tagValues());
|
|
||||||
|
|
||||||
// ->tagValuesOld() return a Collection of old values
|
|
||||||
$this->assertCount(4,$oo->tagValuesOld());
|
|
||||||
|
|
||||||
// ->render_item_old() should be the raw value (unless an md5attribute, then the md5 value)
|
|
||||||
$this->assertEquals('inetOrgPerson',$oo->render_item_old('0'));
|
|
||||||
// ->render_item_new() should be the raw value (unless an md5attribute, then the md5 value)
|
|
||||||
$this->assertEquals('inetLocalMailRecipient',$oo->render_item_new('4'));
|
|
||||||
|
|
||||||
// ->isDirty processing when there is a new value in the _null_ key and in another key (it should be ignored for no_attr_tags attributes)
|
|
||||||
// ->isDirty processing when there is a new value, and its an md5 attribute
|
|
||||||
$this->assertTrue($oo->isDirty());
|
|
||||||
$this->assertCount(2,$x=$o->getDirty());
|
|
||||||
$this->assertArrayHasKey('objectclass',$x);
|
|
||||||
$this->assertCount(5,$x['objectclass']);
|
|
||||||
$this->assertEquals($newoc,$x['objectclass']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_userpassword()
|
|
||||||
{
|
|
||||||
// Test ObjectClass, which can NOT have attribute tags
|
|
||||||
$o = $this->read();
|
|
||||||
$new = [
|
|
||||||
'test1234',
|
|
||||||
];
|
|
||||||
$o->userpassword = [
|
|
||||||
'_null_' => $new,
|
|
||||||
];
|
|
||||||
|
|
||||||
$oo = $o->getObject('userpassword');
|
|
||||||
|
|
||||||
$this->assertInstanceOf(Attribute\Password::class,$oo);
|
|
||||||
$this->assertTrue($oo->no_attr_tags);
|
|
||||||
|
|
||||||
// ->values returns a Collection of values
|
|
||||||
// ->_values is array with only 1 key _null_ with an array of values
|
|
||||||
$this->assertCount(1,$oo->values);
|
|
||||||
$this->assertArrayNotHasKey(Entry::TAG_NOTAG,$oo->values);
|
|
||||||
|
|
||||||
// ->values_old return a Collection of old values
|
|
||||||
// ->_values_old is array with only 1 key _null_ with an array of values
|
|
||||||
$this->assertCount(1,$oo->values_old);
|
|
||||||
$this->assertArrayNotHasKey(Entry::TAG_NOTAG,$oo->values_old);
|
|
||||||
|
|
||||||
// ->tagValues() returns a Collection of values
|
|
||||||
$this->assertCount(1,$oo->tagValues());
|
|
||||||
|
|
||||||
// ->tagValuesOld() return a Collection of old values
|
|
||||||
$this->assertCount(1,$oo->tagValuesOld());
|
|
||||||
|
|
||||||
// ->render_item_old() should be the raw value (unless an md5attribute, then the md5 value)
|
|
||||||
$this->assertEquals('{*clear*}****************',$oo->render_item_old('0'));
|
|
||||||
// ->render_item_new() should be the raw value (unless an md5attribute, then the md5 value)
|
|
||||||
$this->assertEquals('****************',$oo->render_item_new('0'));
|
|
||||||
|
|
||||||
// ->isDirty processing when there is a new value in the _null_ key and in another key (it should be ignored for no_attr_tags attributes)
|
|
||||||
// ->isDirty processing when there is a new value, and its an md5 attribute
|
|
||||||
$this->assertTrue($oo->isDirty());
|
|
||||||
$this->assertCount(3,$x=$o->getDirty());
|
|
||||||
$this->assertArrayHasKey('userpassword',$x);
|
|
||||||
$this->assertCount(1,$x['userpassword']);
|
|
||||||
$this->assertEquals($new,$x['userpassword']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function test_userpassword_nochange()
|
|
||||||
{
|
|
||||||
// Test ObjectClass, which can NOT have attribute tags
|
|
||||||
$o = $this->read();
|
|
||||||
$new = [
|
|
||||||
'd88d98df6727f87376c93e9676978146', // eatmyshorts
|
|
||||||
];
|
|
||||||
$o->userpassword = [
|
|
||||||
'_null_' => $new,
|
|
||||||
];
|
|
||||||
|
|
||||||
$oo = $o->getObject('userpassword');
|
|
||||||
|
|
||||||
$this->assertInstanceOf(Attribute\Password::class,$oo);
|
|
||||||
$this->assertTrue($oo->no_attr_tags);
|
|
||||||
|
|
||||||
// ->values returns a Collection of values
|
|
||||||
// ->_values is array with only 1 key _null_ with an array of values
|
|
||||||
$this->assertCount(1,$oo->values);
|
|
||||||
$this->assertArrayNotHasKey(Entry::TAG_NOTAG,$oo->values);
|
|
||||||
|
|
||||||
// ->values_old return a Collection of old values
|
|
||||||
// ->_values_old is array with only 1 key _null_ with an array of values
|
|
||||||
$this->assertCount(1,$oo->values_old);
|
|
||||||
$this->assertArrayNotHasKey(Entry::TAG_NOTAG,$oo->values_old);
|
|
||||||
|
|
||||||
// ->tagValues() returns a Collection of values
|
|
||||||
$this->assertCount(1,$oo->tagValues());
|
|
||||||
|
|
||||||
// ->tagValuesOld() return a Collection of old values
|
|
||||||
$this->assertCount(1,$oo->tagValuesOld());
|
|
||||||
|
|
||||||
// ->render_item_old() should be the raw value (unless an md5attribute, then the md5 value)
|
|
||||||
$this->assertEquals('{*clear*}****************',$oo->render_item_old('0'));
|
|
||||||
// ->render_item_new() should be the raw value (unless an md5attribute, then the md5 value)
|
|
||||||
$this->assertEquals('****************',$oo->render_item_new('0'));
|
|
||||||
|
|
||||||
// ->isDirty processing when there is a new value in the _null_ key and in another key (it should be ignored for no_attr_tags attributes)
|
|
||||||
// ->isDirty processing when there is a new value, and its an md5 attribute
|
|
||||||
$this->assertFalse($oo->isDirty());
|
|
||||||
$this->assertCount(2,$x=$o->getDirty());
|
|
||||||
$this->assertArrayNotHasKey('userpassword',$x);
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,6 +20,6 @@ class GetBaseDNTest extends TestCase
|
|||||||
|
|
||||||
$this->assertIsObject($o);
|
$this->assertIsObject($o);
|
||||||
$this->assertCount(6,$o->toArray());
|
$this->assertCount(6,$o->toArray());
|
||||||
$this->assertEquals('c=AU',$o->first()->getDn());
|
$this->assertEquals('dc=Test',$o->first()->getDn());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,48 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature;
|
|
||||||
|
|
||||||
use Illuminate\Http\UploadedFile;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Support\Facades\Crypt;
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class ImportTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testLDIF_Import()
|
|
||||||
{
|
|
||||||
$dn = 'cn=Bart Simpson,ou=People,o=Simpsons';
|
|
||||||
$import_file = __DIR__.'/data/ldif-import.ldif';
|
|
||||||
|
|
||||||
$this->assertTrue($this->login());
|
|
||||||
$this->assertTrue(Auth::check());
|
|
||||||
$this->actingAs(Auth::user());
|
|
||||||
$this->assertFalse(config('ldap.cache.enabled'));
|
|
||||||
|
|
||||||
// Check that it exists
|
|
||||||
$this->assertEquals($dn,$x=config('server')->fetch($dn));
|
|
||||||
$this->assertTrue($x->exists);
|
|
||||||
|
|
||||||
// Delete the entry
|
|
||||||
$x->delete();
|
|
||||||
$this->assertEquals(NULL,config('server')->fetch($dn));
|
|
||||||
|
|
||||||
$file = new UploadedFile($import_file,'ldif-import.ldif',null,null,true);
|
|
||||||
|
|
||||||
$response = $this
|
|
||||||
->actingAs(Auth::user())
|
|
||||||
->from('/import')
|
|
||||||
->post('/import/process/ldif',[
|
|
||||||
'_token' => csrf_token(),
|
|
||||||
'key'=>Crypt::encryptString('*import|_NOP'),
|
|
||||||
'file' => $file,
|
|
||||||
]);
|
|
||||||
|
|
||||||
//$response->dump();
|
|
||||||
$response->assertSuccessful();
|
|
||||||
|
|
||||||
// Check that it hsa been created
|
|
||||||
$this->assertEquals($dn,$x=config('server')->fetch($dn));
|
|
||||||
$this->assertTrue($x->exists);
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
use LdapRecord\Container;
|
||||||
use Illuminate\Support\Facades\Session;
|
use LdapRecord\Testing\DirectoryFake;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class LoginTest extends TestCase
|
class LoginTest extends TestCase
|
||||||
@ -18,10 +18,12 @@ class LoginTest extends TestCase
|
|||||||
|
|
||||||
public function test_admin_dn_login()
|
public function test_admin_dn_login()
|
||||||
{
|
{
|
||||||
$this->assertTrue($this->login());
|
$username = 'cn=Admin,dc=Test';
|
||||||
$this->assertTrue(Auth::check());
|
$password = 'test';
|
||||||
|
|
||||||
$this->assertTrue(Session::has('username_encrypt'));
|
//DirectoryFake::setup();
|
||||||
$this->assertTrue(Session::has('password_encrypt'));
|
|
||||||
|
$connection = Container::getDefaultConnection();
|
||||||
|
$this->assertTrue($connection->auth()->attempt($username,$password));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,83 +0,0 @@
|
|||||||
# LDIF Export for cn=Bart Simpson,ou=People,o=Simpsons
|
|
||||||
# Server: LDAP Server (ldap://ldap:389)
|
|
||||||
# Total Entries: 1
|
|
||||||
#
|
|
||||||
# Generated by PLA (http://localhost) on January 12, 2024 12:39 pm
|
|
||||||
# Exported by Anonymous
|
|
||||||
# Version: v2.0.0-dev-00000000
|
|
||||||
|
|
||||||
version: 1
|
|
||||||
# Entry 1: cn=Bart Simpson,ou=People,o=Simpsons
|
|
||||||
dn: cn=Bart Simpson,ou=People,o=Simpsons
|
|
||||||
audio: test
|
|
||||||
cn: Bart Simpson
|
|
||||||
gidNumber: 1000
|
|
||||||
givenName: Bart
|
|
||||||
homeDirectory: /home/users/simpsons/bart
|
|
||||||
jpegPhoto:: /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkS
|
|
||||||
Ew8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRg
|
|
||||||
yIRwhMjIyMj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O/wC2N/RN/wCKKNdozmEEs
|
|
||||||
V3ah1ToulySJd3yq0f5TZG0mz+VtB2/XVG1K7TXby6uYnDwXNyIELcZij4ZcH1Kycf8RqJ8O4SG
|
|
||||||
2ytyskQUSyCdUWKQNmbxgeWzz288+uR7o2wWFiI1Kx/jG52KfJd02B8uMceVBsbkd9OAOfoT6Lj
|
|
||||||
xYKU0W91CadIILCZ7aKF2YoN3iSu+U/kggMeeBkZxxms9VXEsustBOgWa2yjkMDyVXI44425482
|
|
||||||
I8qYf4PWY2tyHYs5it3JPc5Qj900prqZ7m9uJ5PyksryNn1LEn9tD2UEEEQnYPufr5laXZxpmqN
|
|
||||||
537B4nLyWqiiimrbrZaNHBfwTvnYjhmwxGD5Nx/FOGx54x503JpvAtd65mfAWMcZkY8KOOOTik/
|
|
||||||
TS6GnXwtPN+rBjb7LUupwCGYcHsCU24J7jt3NVKiibWTRRvdYXPv6WWY2gjEYE410+eq0f4Mrn/
|
|
||||||
eMf8AR0UyKK2P0sH8QsZvu5qOvdB0fUpvGvtLsrmXj45oFc8duSKX19DHbas0ESLHHFqLhVUYCg
|
|
||||||
oxwB9qmlSv1klNd1TP+r1OL/qji/t0OxwXph19CmO0Ux0E2Lq/i/iW8Kj7LzKf2CqV1/08NG6mM
|
|
||||||
1rKEt78GZYcZEbDAcY8gSQRz5txxVv6KfZrkyfpYpyfsT8f99ZdddI6vruoxX2nvbyJHAIzBK5R
|
|
||||||
shmJKnBBzkDBx271dwdsMtOwTC7c/MqOWeqgiL6RxD+Fj3/0ehSlK3APAib55K/1GvNtyT2iUeu
|
|
||||||
4t/UKmYuntbmjWRdLk2sPOaL+3Wy36K1S+mneVo4PD2xiGSZhzjJPwZBBDAefY1NM/Z6H7nSN6B
|
|
||||||
xPgCSo48d2okG5vHrut9QAoXT9PXWdcs9Iadne6lEblB8MSnkkj1wDgHPtin1pvT0dleNczSidw
|
|
||||||
FEYClVUjPxbckbjnvjypadM6JaaLrcGo6prOkWMFhcMqx+MP8Y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JJPJJJJJPJJoopOc5xu43SZGyMWYLDuXRRRRTU9f//Z
|
|
||||||
l: Springfield
|
|
||||||
mail: bart.simpson@example.com
|
|
||||||
o: The Simpsons
|
|
||||||
objectClass: inetOrgPerson
|
|
||||||
objectClass: posixAccount
|
|
||||||
objectClass: top
|
|
||||||
objectClass: shadowAccount
|
|
||||||
sn: Simpson
|
|
||||||
st: 742 Evergreen Terrace
|
|
||||||
telephoneNumber: +1 939 555 3126
|
|
||||||
uid: bart
|
|
||||||
uidNumber: 1000
|
|
||||||
userPassword: eatmyshorts
|
|
@ -3,21 +3,11 @@
|
|||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
use Illuminate\Support\Facades\Auth;
|
|
||||||
use Illuminate\Support\Facades\Config;
|
|
||||||
|
|
||||||
use App\Classes\LDAP\Server;
|
|
||||||
|
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
use CreatesApplication;
|
use CreatesApplication;
|
||||||
|
|
||||||
protected function setUp(): void
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
Config::set('server',new Server());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hack to get testing working
|
* Hack to get testing working
|
||||||
*/
|
*/
|
||||||
@ -29,15 +19,4 @@ abstract class TestCase extends BaseTestCase
|
|||||||
app()->instance('config', $config);
|
app()->instance('config', $config);
|
||||||
app()->instance('events', $events);
|
app()->instance('events', $events);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function login(): bool
|
|
||||||
{
|
|
||||||
//$username = 'cn=AdminUser,dc=Test';
|
|
||||||
$username = 'admin';
|
|
||||||
$password = 'password';
|
|
||||||
|
|
||||||
$this->post('/login',['uid'=>$username,'password'=>$password]);
|
|
||||||
|
|
||||||
return Auth::check() && (Auth::user()->getDN() === 'cn=AdminUser,dc=Test');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user