Skip to content

A free open source IT asset/license management system

Removed checkbox, refactor for common static method for shouldUseSaslExternal

snipe323ed7e72b88
diff --git a/app/Console/Commands/LdapTroubleshooter.php b/app/Console/Commands/LdapTroubleshooter.php
index db66945395..52a472849f 100644
--- a/app/Console/Commands/LdapTroubleshooter.php
+++ b/app/Console/Commands/LdapTroubleshooter.php
@@ -167,7 +167,7 @@ class LdapTroubleshooter extends Command
$output[] = '-H '.$settings->ldap_server;
$output[] = '-b '.escapeshellarg($settings->ldap_basedn);
- if ($settings->ldap_use_sasl_external_bind) {
+ if (Ldap::shouldUseSaslExternal($settings)) {
// SASL EXTERNAL identifies the client TLS
// cert loaded above (LDAPTLS_CERT / LDAPTLS_KEY) instead
// of a bind DN + password. See the ldapsearch man page's -Y flag.
@@ -395,7 +395,7 @@ class LdapTroubleshooter extends Command
$this->line('STAGE 4: Test Administrative Bind for LDAP Sync');
foreach ($ldap_urls as $ldap_url) {
- if ($settings->ldap_use_sasl_external_bind) {
+ if (Ldap::shouldUseSaslExternal($settings)) {
// SASL EXTERNAL uses the client TLS cert already loaded
// in connect_to_ldap() as the auth identity. No username
// or password gets sent. See GH #19518.
@@ -424,7 +424,7 @@ class LdapTroubleshooter extends Command
$this->debugout('LDAP constants are: '.print_r($ldap_constants, true));
foreach ($ldap_urls as $ldap_url) {
- if ($settings->ldap_use_sasl_external_bind) {
+ if (Ldap::shouldUseSaslExternal($settings)) {
// Password decrypt + username don't apply under SASL
// EXTERNAL - both are null'd in the bind call. The
// informational read after the bind uses the same $settings
@@ -582,9 +582,9 @@ class LdapTroubleshooter extends Command
try { // TODO - copypasta'ed from test_authed_bind
$conn = $this->connect_to_ldap($ldap_url, $check_cert, $start_tls);
// Null $username signals the SASL EXTERNAL branch. The
- // Stage 5 caller sets it that way when
- // ldap_use_sasl_external_bind is on. Post-bind logic is
- // identical either way.
+ // Stage 5 caller sets it that way when the auto-detect
+ // in Ldap::shouldUseSaslExternal() matches. Post-bind logic
+ // is identical either way.
if ($username === null) {
$bind_results = ldap_sasl_bind($conn, null, null, 'EXTERNAL');
$identityLabel = 'the SASL EXTERNAL client certificate';
diff --git a/app/Livewire/LdapSettings.php b/app/Livewire/LdapSettings.php
index 7925608404..ddf8a79068 100644
--- a/app/Livewire/LdapSettings.php
+++ b/app/Livewire/LdapSettings.php
@@ -113,14 +113,6 @@ class LdapSettings extends Component
public string $ldap_client_tls_cert = '';
- // SASL EXTERNAL bind uses the client TLS cert (loaded via
- // LDAP_OPT_X_TLS_CERTFILE / _KEYFILE in Ldap::connectToLdap()) as the
- // authentication identity instead of a bind DN + password. Depends on
- // ldap_client_tls_cert + ldap_client_tls_key being populated. Enables
- // directories like Google Workspace LDAP that authenticate via mTLS
- // certificate.
- public bool $ldap_use_sasl_external_bind = false;
-
// Step 2: Bind credentials
public string $ldap_uname = '';
@@ -280,7 +272,6 @@ class LdapSettings extends Component
$this->ldap_server_cert_ignore = (bool) $setting->ldap_server_cert_ignore;
$this->ldap_client_tls_key = (string) $setting->ldap_client_tls_key;
$this->ldap_client_tls_cert = (string) $setting->ldap_client_tls_cert;
- $this->ldap_use_sasl_external_bind = (bool) $setting->ldap_use_sasl_external_bind;
$this->ldap_uname = (string) $setting->ldap_uname;
// ldap_pword stays ''. See property docstring.
@@ -435,7 +426,6 @@ class LdapSettings extends Component
$setting->ldap_server_cert_ignore = $this->ldap_server_cert_ignore ? '1' : '0';
$setting->ldap_client_tls_key = $this->ldap_client_tls_key;
$setting->ldap_client_tls_cert = $this->ldap_client_tls_cert;
- $setting->ldap_use_sasl_external_bind = $this->ldap_use_sasl_external_bind ? '1' : '0';
$this->persistAndAdvance($setting);
}
@@ -464,15 +454,6 @@ class LdapSettings extends Component
*/
protected function step1SyntaxRules(): array
{
- // Snapshot the form values into locals so the SASL EXTERNAL
- // cross-field rule below sees the CURRENT submission (not the
- // persisted values). Otherwise a user who filled in cert + key
- // and toggled SASL EXTERNAL in the same page load would trip
- // the "cert not configured" guard even though they're one save
- // away from having it configured.
- $tlsCert = trim($this->ldap_client_tls_cert);
- $tlsKey = trim($this->ldap_client_tls_key);
-
return [
'ldap_server' => 'required|starts_with:ldap://,ldaps://',
'ldap_client_tls_key' => [
@@ -510,25 +491,6 @@ class LdapSettings extends Component
}
},
],
- 'ldap_use_sasl_external_bind' => [
- 'nullable',
- 'boolean',
- /** @SuppressWarnings(PHPMD.UnusedFormalParameter) */
- function ($attribute, $value, $fail) use ($tlsCert, $tlsKey) {
- if (! $value) {
- return;
- }
- // SASL EXTERNAL requires the client cert + key. The
- // required_with rules above already gate the pair
- // together. Here we ensure both are populated (not
- // just consistent with each other) before enabling
- // the toggle. Empty pair + SASL toggle on would
- // fail at bind time with a mostly-useless server error.
- if ($tlsCert === '' || $tlsKey === '') {
- $fail(trans('admin/settings/general.ldap_wizard.sasl_external_requires_cert'));
- }
- },
- ],
];
}
@@ -538,7 +500,6 @@ class LdapSettings extends Component
'ldap_server' => trans('admin/settings/general.ldap_server'),
'ldap_client_tls_key' => trans('admin/settings/general.ldap_client_tls_key'),
'ldap_client_tls_cert' => trans('admin/settings/general.ldap_client_tls_cert'),
- 'ldap_use_sasl_external_bind' => trans('admin/settings/general.ldap_use_sasl_external_bind'),
];
}
@@ -662,7 +623,6 @@ class LdapSettings extends Component
}
$setting = Setting::getSettings();
- $setting->ldap_use_sasl_external_bind = $this->ldap_use_sasl_external_bind ? '1' : '0';
$setting->ldap_uname = $this->ldap_uname;
// Only overwrite the persisted encrypted password when the user
// provided a new value. Blank pword = keep-what's-in-DB.
@@ -680,13 +640,24 @@ class LdapSettings extends Component
$this->persistAndAdvance($setting);
}
+ /**
+ * Live-form wrapper around Ldap::shouldUseSaslExternal(). The
+ * component is passed as-is because it carries the four properties
+ * the predicate reads. Blade-accessible via #[Computed].
+ */
+ #[Computed]
+ public function isSaslExternalCandidate(): bool
+ {
+ return Ldap::shouldUseSaslExternal($this);
+ }
+
protected function canAdvanceStep2(): bool
{
- // SASL EXTERNAL mode authenticates via the client cert configured
- // on step 1, so ldap_uname / ldap_pword are optional (and would
- // be ignored on bind if present). Skip the empty-uname gate when
- // SASL EXTERNAL is on.
- if (! $this->ldap_use_sasl_external_bind && trim($this->ldap_uname) === '') {
+ // SASL EXTERNAL (auto-detected in bindAdminToLdap when client
+ // cert + key are populated and uname/pword are blank) skips
+ // the empty-uname gate: those fields are meant to be blank on
+ // that path.
+ if (trim($this->ldap_uname) === '' && ! $this->isSaslExternalCandidate()) {
return false;
}
if (trim($this->ldap_basedn) === '') {
@@ -718,12 +689,10 @@ class LdapSettings extends Component
$normalizeDn = fn ($dn) => strtolower(preg_replace('/\s*,\s*/', ',', trim((string) $dn)));
$bindDn = $normalizeDn($this->ldap_uname);
- // SASL EXTERNAL bind uses the client TLS cert for auth, so
- // ldap_uname / ldap_pword are optional (and unused) when it's
- // on. The flag lives on step 1 (next to the cert/key it
- // depends on). This branch just reads its persisted state to
- // decide requiredness here.
- $sasl = $this->ldap_use_sasl_external_bind;
+ // Auto-detected SASL EXTERNAL (client cert + key populated,
+ // uname/pword blank) uses the TLS cert as the bind identity,
+ // so ldap_uname / ldap_pword are optional on that path.
+ $sasl = $this->isSaslExternalCandidate();
$unameRule = $sasl ? ['nullable', 'max:191'] : 'required|max:191';
$pwordRule = $sasl
? 'nullable'
@@ -796,7 +765,7 @@ class LdapSettings extends Component
$settings = Setting::getSettings();
$server = (string) $settings->ldap_server;
- if ($this->ldap_use_sasl_external_bind) {
+ if ($this->isSaslExternalCandidate()) {
// Success message uses $uname for the "Bound as ..."
// interpolation. Under SASL EXTERNAL there is no bind
// username, the client cert is the identity, so surface
@@ -1615,17 +1584,6 @@ class LdapSettings extends Component
$this->resetValidation($property);
}
- // Toggling is_ad ON hides the SASL EXTERNAL checkbox in the
- // Blade view but doesn't otherwise clear its state, so a user
- // who had SASL on and then flipped to AD mode would be left
- // with a hidden-but-active flag that silently gates uname /
- // pword requiredness on step 2 and picks the SASL bind branch
- // in Ldap::bindAdminToLdap(). Force it off here so the toggle
- // is always false when it isn't visible.
- if ($property === 'is_ad' && $this->is_ad && $this->ldap_use_sasl_external_bind) {
- $this->ldap_use_sasl_external_bind = false;
- }
-
if (! in_array($property, [
'currentStep',
'highestStepReached',
diff --git a/app/Models/Ldap.php b/app/Models/Ldap.php
index ab74efd654..59cb6706ce 100644
--- a/app/Models/Ldap.php
+++ b/app/Models/Ldap.php
@@ -258,31 +258,44 @@ class Ldap extends Model
}
/**
- * Binds/authenticates an admin to LDAP for LDAP searching/syncing.
- * Here we also return a better error if the app key is donked.
+ * Returns true when the given config source (Setting model, live
+ * Livewire component state, whatever) matches the auto-detect
+ * condition that routes bindAdminToLdap through SASL EXTERNAL:
+ * client cert + key are populated AND both bind DN and bind
+ * password are blank.
*
- * @author [A. Gianotto] [<[email protected]>]
+ * Runtime, LDAP troubleshooter, and LDAP Livewire wizard all
+ * evaluate the same.
+ */
+ public static function shouldUseSaslExternal(object $config): bool
+ {
+ return !empty($config->ldap_client_tls_cert)
+ && !empty($config->ldap_client_tls_key)
+ && empty($config->ldap_uname)
+ && empty($config->ldap_pword);
+ }
+
+ /**
+ * Binds/authenticates an admin to LDAP for LDAP searching/syncing.
+ * Modifies state on the passed-in $connection. Throws on any bind
+ * failure with a decoded message (including a friendlier "app key
+ * changed" message for the encrypted-password decrypt path).
+ * Callers wrap in try/catch and rely on the exception, not a
+ * return value.
*
+ * @throws Exception on any bind failure
* @since [v3.0]
*
- * @param bool|false $user
- * @return bool true if the username and/or password provided are valid
- * false if the username and/or password provided are invalid
+ * @author [A. Gianotto] [<[email protected]>]
+ *
*/
- public static function bindAdminToLdap($connection)
+ public static function bindAdminToLdap($connection): void
{
$settings = Setting::getSettings();
- // SASL EXTERNAL bind uses the client TLS cert (already loaded via
- // LDAP_OPT_X_TLS_CERTFILE / _KEYFILE in connectToLdap()) as the
- // authentication identity, so username / password are not sent.
- // Off by default. Opting in requires client cert + key to be
- // configured on step 1 of the LDAP wizard. Enables directories
- // like Google Workspace LDAP that authenticate via mTLS
- // certificate rather than a bind DN + password. See GH #19518.
$ldap_username = $settings->ldap_uname;
- if ($settings->ldap_use_sasl_external_bind) {
+ if (self::shouldUseSaslExternal($settings)) {
if (! @ldap_sasl_bind($connection, null, null, 'EXTERNAL')) {
throw new Exception('Could not bind to LDAP via SASL EXTERNAL: '.self::bindError($connection));
}
@@ -297,11 +310,6 @@ class Ldap extends Model
if (! @ldap_bind($connection, $ldap_username, $ldap_pass)) {
throw new Exception('Could not bind to LDAP: '.self::bindError($connection));
}
- // TODO - this just "falls off the end" but the function states that it should return true or false
- // unfortunately, one of the use cases for this function is wrong and *needs* for that failure mode to fire
- // so I don't want to fix this right now.
- // this method MODIFIES STATE on the passed-in $connection and just returns true or false (or, in this case, undefined)
- // at the next refactor, this should be appropriately modified to be more consistent.
} else {
// LDAP should also work with anonymous bind (no dn, no password available)
if (! @ldap_bind($connection)) {
diff --git a/app/Models/Setting.php b/app/Models/Setting.php
index 008ab64176..89c7d7b5a7 100755
--- a/app/Models/Setting.php
+++ b/app/Models/Setting.php
@@ -426,7 +426,6 @@ class Setting extends Model
'ad_append_domain',
'ldap_client_tls_key',
'ldap_client_tls_cert',
- 'ldap_use_sasl_external_bind',
'ldap_default_group',
'ldap_dept',
'ldap_phone_field',
diff --git a/database/migrations/2026_08_26_010000_add_ldap_use_sasl_external_bind_to_settings.php b/database/migrations/2026_08_26_010000_add_ldap_use_sasl_external_bind_to_settings.php
deleted file mode 100644
index 686077dc26..0000000000
--- a/database/migrations/2026_08_26_010000_add_ldap_use_sasl_external_bind_to_settings.php
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-
-use Illuminate\Database\Migrations\Migration;
-use Illuminate\Database\Schema\Blueprint;
-use Illuminate\Support\Facades\Schema;
-
-/**
- * Opt-in toggle for LDAP SASL EXTERNAL bind. When on, bindAdminToLdap
- * uses ldap_sasl_bind() with the EXTERNAL mechanism (authenticates the
- * caller via the client TLS cert already configured via
- * ldap_client_tls_cert / ldap_client_tls_key) instead of a
- * username/password simple bind. Used by installs that authenticate to
- * their directory with a client cert, notably Google Workspace LDAP
- * (see GH #19518).
- *
- * Off by default so every existing install keeps the simple / anonymous
- * bind behavior it had before.
- */
-return new class extends Migration
-{
- public function up(): void
- {
- Schema::table('settings', function (Blueprint $table) {
- $table->boolean('ldap_use_sasl_external_bind')->default(false)->after('ldap_client_tls_cert');
- });
- }
-
- public function down(): void
- {
- Schema::table('settings', function (Blueprint $table) {
- $table->dropColumn('ldap_use_sasl_external_bind');
- });
- }
-};
diff --git a/resources/lang/en-US/admin/settings/general.php b/resources/lang/en-US/admin/settings/general.php
index cacc217373..89eb496057 100644
--- a/resources/lang/en-US/admin/settings/general.php
+++ b/resources/lang/en-US/admin/settings/general.php
@@ -105,8 +105,8 @@ return [
],
'step_connection_help' => 'Configure how to reach your LDAP or Active Directory server. Once saved, you can test the connection before moving on to bind credentials.',
'ldap_uname_help' => 'The distinguished name (DN) or User Principal Name (UPN) of an admin service account that can search your directory. For Active Directory this is usually a UPN like <code>[email protected]</code>. For OpenLDAP and most other directories this is a full DN like <code>cn=admin,dc=example,dc=com</code>. Enter the entire path including the base DN portion, not just the account name.',
- 'sasl_external_requires_cert' => 'SASL EXTERNAL bind requires a client TLS certificate and key. Configure both on the Connection step before enabling this option.',
'ldap_pword_help' => 'Leave blank to keep the previously-saved password.',
+ 'sasl_external_step2_hint' => 'A client TLS certificate is configured on the previous step. Leave the Bind DN/UPN and Bind Password fields blank to authenticate with the certificate (SASL EXTERNAL). Fill them in only if the server requires cert-plus-bind together.',
'bind' => [
'pword_decrypt_failed' => 'Could not decrypt the stored bind password. This usually means the app key changed since the password was saved. Enter the password again to fix.',
'rejected' => 'The LDAP server rejected the bind (:error). Double-check the username and password.',
@@ -198,7 +198,7 @@ return [
'ldap_enabled' => 'LDAP enabled',
'ldap_integration' => 'LDAP Integration',
'ldap_settings' => 'LDAP Settings',
- 'ldap_client_tls_cert_help' => 'Client-Side TLS Certificate and Key for LDAP connections are usually only useful in Google Workspace configurations with "Secure LDAP." Both are required.',
+ 'ldap_client_tls_cert_help' => 'Client-Side TLS Certificate and Key for LDAP connections are usually only useful in Google Workspace configurations with "Secure LDAP." Both are required. For certificate-based (SASL EXTERNAL) authentication, leave the Bind DN/UPN and Bind Password fields on the next step blank.',
'ldap_location' => 'Location Field',
'ldap_location_help' => 'The LDAP Location field should be used if <strong>an OU is not being used in the Base Bind DN.</strong> Leave this blank if an OU search is being used.',
'ldap_login_test_help' => 'Enter a valid LDAP username and password from the base DN you specified above to test whether your LDAP login is configured correctly. YOU MUST SAVE YOUR UPDATED LDAP SETTINGS FIRST.',
@@ -214,8 +214,6 @@ return [
'ldap_tls' => 'Use TLS',
'ldap_tls_help' => 'This should be checked only if you are running STARTTLS on your LDAP server. ',
'ldap_uname' => 'LDAP Bind DN/UPN',
- 'ldap_use_sasl_external_bind' => 'Use SASL EXTERNAL bind (authenticate with client certificate)',
- 'ldap_use_sasl_external_bind_help' => 'When enabled, Snipe-IT authenticates to the directory using the client TLS certificate and key configured on the Server step, and the Bind DN/UPN and Bind Password below are ignored. Required for Google Workspace LDAP deployments that use certificate-based authentication.',
'ldap_dept' => 'Department Field',
'ldap_phone' => 'Phone Number Field',
'ldap_jobtitle' => 'Job Title Field',
diff --git a/resources/views/livewire/ldap-settings.blade.php b/resources/views/livewire/ldap-settings.blade.php
index 0ef3f680f8..7e39e40f04 100644
--- a/resources/views/livewire/ldap-settings.blade.php
+++ b/resources/views/livewire/ldap-settings.blade.php
@@ -462,26 +462,6 @@
</x-slot:input>
</x-form.row>
- {{-- SASL EXTERNAL bind toggle. Lives next to the cert /
- key fields it depends on. Its state makes the Bind
- DN/UPN + Bind Password fields on step 2 optional.
- Hidden when is_ad is on: Active Directory servers
- support cert-based auth only under a specific AD
- Certificate Services / cert-mapping deployment that
- almost nobody runs, and cluttering the AD-common
- path with an option nobody uses would confuse more
- than it helps. --}}
- @if (! $is_ad)
- <x-form.checkbox-row
- name="ldap_use_sasl_external_bind"
- wire:model.live="ldap_use_sasl_external_bind"
- :label="trans('admin/settings/general.ldap_use_sasl_external_bind')"
- :checked="$ldap_use_sasl_external_bind"
- help_text="{!! trans('admin/settings/general.ldap_use_sasl_external_bind_help') !!}"
- :disabled="$isReadOnly"
- />
- @endif
-
@elseif ($currentStep === 2)
{{-- Merged Authenticate + Scope step. Bind credentials
appear next to the base DN so users composing a
@@ -489,12 +469,23 @@
alongside. That was the friction that pushed us
to combine what used to be two separate steps. --}}
+ {{-- Only renders when a client cert AND key are
+ populated on step 1, which is the only case
+ where leaving the bind fields blank does
+ something meaningful. --}}
+ @if ($ldap_client_tls_cert !== '' && $ldap_client_tls_key !== '')
+ <x-alert type="info" icon="tip">
+ {{ trans('admin/settings/general.ldap_wizard.sasl_external_step2_hint') }}
+ </x-alert>
+ @endif
+
<!-- Base Bind DN, placed first so users compose their
admin DN with the base DN already visible. -->
<x-form.row
name="ldap_basedn"
:label="trans('admin/settings/general.ldap_basedn')"
help_text="{!! trans('admin/settings/general.ldap_wizard.ldap_basedn_help') !!}"
+ help_class="col-md-7 col-md-offset-3"
>
<x-slot:input>
<x-input.text
@@ -513,6 +504,7 @@
name="ldap_uname"
:label="trans('admin/settings/general.ldap_uname')"
help_html="{!! trans('admin/settings/general.ldap_wizard.ldap_uname_help') !!}"
+ help_class="col-md-7 col-md-offset-3"
>
<x-slot:input>
{{-- Placeholder swaps based on the step-1 AD flag:
@@ -524,8 +516,8 @@
wire:model.live.debounce.500ms="ldap_uname"
placeholder="{{ trans('general.example').($is_ad ? '[email protected]' : 'cn=admin,dc=example,dc=com') }}"
:ignore-autofill="true"
- :required="! $ldap_use_sasl_external_bind"
- :readonly="$isReadOnly || $ldap_use_sasl_external_bind"
+ :required="! ($ldap_client_tls_cert !== '' && $ldap_client_tls_key !== '')"
+ :readonly="$isReadOnly"
/>
</x-slot:input>
</x-form.row>
@@ -535,14 +527,15 @@
name="ldap_pword"
:label="trans('admin/settings/general.ldap_pword')"
help_text="{!! trans('admin/settings/general.ldap_wizard.ldap_pword_help') !!}"
+ help_class="col-md-7 col-md-offset-3"
>
<x-slot:input>
<x-input.password
name="ldap_pword"
wire:model.live.debounce.500ms="ldap_pword"
- :required="! $ldap_use_sasl_external_bind"
+ :required="! ($ldap_client_tls_cert !== '' && $ldap_client_tls_key !== '')"
:ignore-autofill="true"
- :readonly="$isReadOnly || $ldap_use_sasl_external_bind"
+ :readonly="$isReadOnly"
/>
</x-slot:input>
</x-form.row>
@@ -552,6 +545,7 @@
name="ldap_filter"
:label="trans('admin/settings/general.ldap_filter')"
help_text="{!! trans('admin/settings/general.ldap_wizard.ldap_filter_help') !!}"
+ help_class="col-md-7 col-md-offset-3"
>
<x-slot:input>
<x-input.text
@@ -569,6 +563,7 @@
name="ldap_auth_filter_query"
:label="trans('admin/settings/general.ldap_auth_filter_query')"
help_text="{!! trans('admin/settings/general.ldap_wizard.ldap_auth_filter_query_help') !!}"
+ help_class="col-md-7 col-md-offset-3"
>
<x-slot:input>
<x-input.text
@@ -819,7 +814,6 @@
'ldap_server_cert_ignore' => trans('admin/settings/general.ldap_server_cert_ignore'),
'is_ad' => trans('admin/settings/general.is_ad'),
'ad_domain' => trans('admin/settings/general.ad_domain'),
- 'ldap_use_sasl_external_bind' => trans('admin/settings/general.ldap_use_sasl_external_bind'),
],
],
2 => [
diff --git a/tests/Unit/LdapTest.php b/tests/Unit/LdapTest.php
index 7aaf9d788c..d48b142653 100644
--- a/tests/Unit/LdapTest.php
+++ b/tests/Unit/LdapTest.php
@@ -94,13 +94,19 @@ class LdapTest extends TestCase
$this->assertNull(Ldap::bindAdminToLdap('dummy'));
}
- public function test_sasl_external_bind_when_setting_is_on()
+ public function test_sasl_external_bind_when_cert_and_key_present_without_credentials()
{
// GH #19518: SASL EXTERNAL bind (auth via client TLS cert)
- // must route through ldap_sasl_bind, not ldap_bind. Username
- // and password on the setting must be ignored.
+ // must route through ldap_sasl_bind, not ldap_bind. Auto-detect
+ // fires when cert + key are populated AND both bind DN and
+ // bind password are blank.
$this->settings->enableLdap();
- $this->settings->set(['ldap_use_sasl_external_bind' => 1]);
+ $this->settings->set([
+ 'ldap_client_tls_cert' => 'CERT PEM',
+ 'ldap_client_tls_key' => 'KEY PEM',
+ 'ldap_uname' => '',
+ 'ldap_pword' => '',
+ ]);
$this->getFunctionMock('App\\Models', 'ldap_sasl_bind')
->expects($this->once())
@@ -115,7 +121,12 @@ class LdapTest extends TestCase
public function test_sasl_external_bind_failure_surfaces_error()
{
$this->settings->enableLdap();
- $this->settings->set(['ldap_use_sasl_external_bind' => 1]);
+ $this->settings->set([
+ 'ldap_client_tls_cert' => 'CERT PEM',
+ 'ldap_client_tls_key' => 'KEY PEM',
+ 'ldap_uname' => '',
+ 'ldap_pword' => '',
+ ]);
$this->getFunctionMock('App\\Models', 'ldap_sasl_bind')
->expects($this->once())
@@ -132,12 +143,13 @@ class LdapTest extends TestCase
$this->assertNull(Ldap::bindAdminToLdap('dummy'));
}
- public function test_simple_bind_still_used_when_sasl_external_is_off()
+ public function test_simple_bind_still_used_when_credentials_are_present()
{
- // Regression guard: existing installs (SASL EXTERNAL off, which
- // is the default) must keep the pre-#19518 simple-bind path.
+ // Regression guard: cert + key populated but the user has ALSO
+ // filled in bind DN / password picks the simple-bind path, not
+ // SASL EXTERNAL. Also the default configuration case for every
+ // pre-#19518 install.
$this->settings->enableLdap();
- $this->settings->set(['ldap_use_sasl_external_bind' => 0]);
$this->getFunctionMock('App\\Models', 'ldap_bind')
->expects($this->once())