Skip to content

Commit 8358412

Browse files
justusbunsiSysoev, Vladimir
authored and
Sysoev, Vladimir
committed
Allow enable LDAP source and disable user sync via CLI (go-gitea#20206)
The current `admin auth` CLI for managing authentication source of type LDAP via BindDN and Simple LDAP does not allow enabling the respective source, once disabled via `--not-active`. The same applies to `--synchronize-users` specifially for LDAP via BindDN. These changes add two new flags to LDAP related CLI commands: - `--active` for both LDAP authentication source types - `--disable-synchronize-users` for LDAP via BindDN Signed-off-by: justusbunsi <[email protected]>
1 parent 219e73e commit 8358412

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

cmd/admin_auth_ldap.go

+14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ var (
3434
Name: "not-active",
3535
Usage: "Deactivate the authentication source.",
3636
},
37+
cli.BoolFlag{
38+
Name: "active",
39+
Usage: "Activate the authentication source.",
40+
},
3741
cli.StringFlag{
3842
Name: "security-protocol",
3943
Usage: "Security protocol name.",
@@ -117,6 +121,10 @@ var (
117121
Name: "synchronize-users",
118122
Usage: "Enable user synchronization.",
119123
},
124+
cli.BoolFlag{
125+
Name: "disable-synchronize-users",
126+
Usage: "Disable user synchronization.",
127+
},
120128
cli.UintFlag{
121129
Name: "page-size",
122130
Usage: "Search page size.",
@@ -183,9 +191,15 @@ func parseAuthSource(c *cli.Context, authSource *auth.Source) {
183191
if c.IsSet("not-active") {
184192
authSource.IsActive = !c.Bool("not-active")
185193
}
194+
if c.IsSet("active") {
195+
authSource.IsActive = c.Bool("active")
196+
}
186197
if c.IsSet("synchronize-users") {
187198
authSource.IsSyncEnabled = c.Bool("synchronize-users")
188199
}
200+
if c.IsSet("disable-synchronize-users") {
201+
authSource.IsSyncEnabled = !c.Bool("disable-synchronize-users")
202+
}
189203
}
190204

191205
// parseLdapConfig assigns values on config according to command line flags.

cmd/admin_auth_ldap_test.go

+57
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,36 @@ func TestUpdateLdapBindDn(t *testing.T) {
858858
},
859859
errMsg: "Invalid authentication type. expected: LDAP (via BindDN), actual: OAuth2",
860860
},
861+
// case 24
862+
{
863+
args: []string{
864+
"ldap-test",
865+
"--id", "24",
866+
"--name", "ldap (via Bind DN) flip 'active' and 'user sync' attributes",
867+
"--active",
868+
"--disable-synchronize-users",
869+
},
870+
id: 24,
871+
existingAuthSource: &auth.Source{
872+
Type: auth.LDAP,
873+
IsActive: false,
874+
IsSyncEnabled: true,
875+
Cfg: &ldap.Source{
876+
Name: "ldap (via Bind DN) flip 'active' and 'user sync' attributes",
877+
Enabled: true,
878+
},
879+
},
880+
authSource: &auth.Source{
881+
Type: auth.LDAP,
882+
Name: "ldap (via Bind DN) flip 'active' and 'user sync' attributes",
883+
IsActive: true,
884+
IsSyncEnabled: false,
885+
Cfg: &ldap.Source{
886+
Name: "ldap (via Bind DN) flip 'active' and 'user sync' attributes",
887+
Enabled: true,
888+
},
889+
},
890+
},
861891
}
862892

863893
for n, c := range cases {
@@ -1221,6 +1251,33 @@ func TestUpdateLdapSimpleAuth(t *testing.T) {
12211251
},
12221252
errMsg: "Invalid authentication type. expected: LDAP (simple auth), actual: PAM",
12231253
},
1254+
// case 20
1255+
{
1256+
args: []string{
1257+
"ldap-test",
1258+
"--id", "20",
1259+
"--name", "ldap (simple auth) flip 'active' attribute",
1260+
"--active",
1261+
},
1262+
id: 20,
1263+
existingAuthSource: &auth.Source{
1264+
Type: auth.DLDAP,
1265+
IsActive: false,
1266+
Cfg: &ldap.Source{
1267+
Name: "ldap (simple auth) flip 'active' attribute",
1268+
Enabled: true,
1269+
},
1270+
},
1271+
authSource: &auth.Source{
1272+
Type: auth.DLDAP,
1273+
Name: "ldap (simple auth) flip 'active' attribute",
1274+
IsActive: true,
1275+
Cfg: &ldap.Source{
1276+
Name: "ldap (simple auth) flip 'active' attribute",
1277+
Enabled: true,
1278+
},
1279+
},
1280+
},
12241281
}
12251282

12261283
for n, c := range cases {

0 commit comments

Comments
 (0)