Skip to content
Merged
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
22 changes: 11 additions & 11 deletions src/Query/Model/ActiveDirectoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function findBySidOrFail(string $sid, array $columns = ['*']): Model
public function whereEnabled(): static
{
return $this->notFilter(
fn ($query) => $query->whereDisabled()
fn (self $query) => $query->whereDisabled()
);
}

Expand All @@ -60,7 +60,7 @@ public function whereDisabled(): static
public function whereMember(string $dn, bool $nested = false): static
{
return $this->nestedMatchQuery(
fn ($attribute) => $this->whereEquals($attribute, $dn),
fn (string $attribute) => $this->whereEquals($attribute, $this->substituteBaseDn($dn)),
'member',
$nested
);
Expand All @@ -72,7 +72,7 @@ public function whereMember(string $dn, bool $nested = false): static
public function orWhereMember(string $dn, bool $nested = false): static
{
return $this->nestedMatchQuery(
fn ($attribute) => $this->orWhereEquals($attribute, $dn),
fn (string $attribute) => $this->orWhereEquals($attribute, $this->substituteBaseDn($dn)),
'member',
$nested
);
Expand All @@ -84,7 +84,7 @@ public function orWhereMember(string $dn, bool $nested = false): static
public function whereMemberOf(string $dn, bool $nested = false): static
{
return $this->nestedMatchQuery(
fn ($attribute) => $this->whereEquals($attribute, $dn),
fn (string $attribute) => $this->whereEquals($attribute, $this->substituteBaseDn($dn)),
'memberof',
$nested
);
Expand All @@ -96,7 +96,7 @@ public function whereMemberOf(string $dn, bool $nested = false): static
public function whereNotMemberof(string $dn, bool $nested = false): static
{
return $this->nestedMatchQuery(
fn ($attribute) => $this->whereNotEquals($attribute, $dn),
fn (string $attribute) => $this->whereNotEquals($attribute, $this->substituteBaseDn($dn)),
'memberof',
$nested
);
Expand All @@ -108,7 +108,7 @@ public function whereNotMemberof(string $dn, bool $nested = false): static
public function orWhereMemberOf(string $dn, bool $nested = false): static
{
return $this->nestedMatchQuery(
fn ($attribute) => $this->orWhereEquals($attribute, $dn),
fn (string $attribute) => $this->orWhereEquals($attribute, $this->substituteBaseDn($dn)),
'memberof',
$nested
);
Expand All @@ -120,7 +120,7 @@ public function orWhereMemberOf(string $dn, bool $nested = false): static
public function orWhereNotMemberof(string $dn, bool $nested = false): static
{
return $this->nestedMatchQuery(
fn ($attribute) => $this->orWhereNotEquals($attribute, $dn),
fn (string $attribute) => $this->orWhereNotEquals($attribute, $this->substituteBaseDn($dn)),
'memberof',
$nested
);
Expand All @@ -132,7 +132,7 @@ public function orWhereNotMemberof(string $dn, bool $nested = false): static
public function whereManager(string $dn, bool $nested = false): static
{
return $this->nestedMatchQuery(
fn ($attribute) => $this->whereEquals($attribute, $dn),
fn (string $attribute) => $this->whereEquals($attribute, $this->substituteBaseDn($dn)),
'manager',
$nested
);
Expand All @@ -144,7 +144,7 @@ public function whereManager(string $dn, bool $nested = false): static
public function whereNotManager(string $dn, bool $nested = false): static
{
return $this->nestedMatchQuery(
fn ($attribute) => $this->whereNotEquals($attribute, $dn),
fn (string $attribute) => $this->whereNotEquals($attribute, $this->substituteBaseDn($dn)),
'manager',
$nested
);
Expand All @@ -156,7 +156,7 @@ public function whereNotManager(string $dn, bool $nested = false): static
public function orWhereManager(string $dn, bool $nested = false): static
{
return $this->nestedMatchQuery(
fn ($attribute) => $this->orWhereEquals($attribute, $dn),
fn (string $attribute) => $this->orWhereEquals($attribute, $this->substituteBaseDn($dn)),
'manager',
$nested
);
Expand All @@ -168,7 +168,7 @@ public function orWhereManager(string $dn, bool $nested = false): static
public function orWhereNotManager(string $dn, bool $nested = false): static
{
return $this->nestedMatchQuery(
fn ($attribute) => $this->orWhereNotEquals($attribute, $dn),
fn (string $attribute) => $this->orWhereNotEquals($attribute, $this->substituteBaseDn($dn)),
'manager',
$nested
);
Expand Down
55 changes: 55 additions & 0 deletions tests/Unit/Query/Model/ActiveDirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ public function test_where_member_of()
$this->assertEquals('(memberof=cn=Accounting,dc=org,dc=acme)', $b->getUnescapedQuery());
}

public function test_where_member_of_substitutes_base_dn()
{
$b = $this->newBuilder();
$b->setBaseDn('dc=org,dc=acme');
$b->whereMemberOf('cn=Accounting,{base}');
$where = $b->filters['and'][0];
$this->assertEquals('memberof', $where['field']);
$this->assertEquals('=', $where['operator']);
$this->assertEquals(
'\63\6e\3d\41\63\63\6f\75\6e\74\69\6e\67\2c\64\63\3d\6f\72\67\2c\64\63\3d\61\63\6d\65',
$where['value']
);
$this->assertEquals(
'(memberof=cn=Accounting,dc=org,dc=acme)',
$b->getUnescapedQuery()
);
}

public function test_where_member_of_nested()
{
$b = $this->newBuilder();
Expand All @@ -43,6 +61,24 @@ public function test_where_member_of_nested()
$this->assertEquals('(memberof:1.2.840.113556.1.4.1941:=cn=Accounting,dc=org,dc=acme)', $b->getUnescapedQuery());
}

public function test_where_member_of_nested_substitutes_base_dn()
{
$b = $this->newBuilder();
$b->setBaseDn('dc=org,dc=acme');
$b->whereMemberOf('cn=Accounting,{base}', $nested = true);
$where = $b->filters['and'][0];
$this->assertEquals('memberof:1.2.840.113556.1.4.1941:', $where['field']);
$this->assertEquals('=', $where['operator']);
$this->assertEquals(
'\63\6e\3d\41\63\63\6f\75\6e\74\69\6e\67\2c\64\63\3d\6f\72\67\2c\64\63\3d\61\63\6d\65',
$where['value']
);
$this->assertEquals(
'(memberof:1.2.840.113556.1.4.1941:=cn=Accounting,dc=org,dc=acme)',
$b->getUnescapedQuery()
);
}

public function test_or_where_member_of()
{
$b = $this->newBuilder();
Expand All @@ -61,6 +97,25 @@ public function test_or_where_member_of()
);
}

public function test_or_where_member_of_substitutes_base_dn()
{
$b = $this->newBuilder();
$b->setBaseDn('dc=org,dc=acme');
$b->orWhereEquals('cn', 'John Doe');
$b->orWhereMemberOf('cn=Accounting,{base}');
$where = $b->filters['or'][1];
$this->assertEquals('memberof', $where['field']);
$this->assertEquals('=', $where['operator']);
$this->assertEquals(
'\63\6e\3d\41\63\63\6f\75\6e\74\69\6e\67\2c\64\63\3d\6f\72\67\2c\64\63\3d\61\63\6d\65',
$where['value']
);
$this->assertEquals(
'(|(cn=John Doe)(memberof=cn=Accounting,dc=org,dc=acme))',
$b->getUnescapedQuery()
);
}

public function test_or_where_member_of_nested()
{
$b = $this->newBuilder();
Expand Down