How to use Bind method of models Package

Best Keploy code snippet using models.Bind

admin_auth_ldap_test.go

Source:admin_auth_ldap_test.go Github

copy

Full Screen

...8 "code.gitea.io/gitea/modules/auth/ldap"9 "github.com/stretchr/testify/assert"10 "github.com/urfave/cli"11)12func TestAddLdapBindDn(t *testing.T) {13 // Mock cli functions to do not exit on error14 var osExiter = cli.OsExiter15 defer func() { cli.OsExiter = osExiter }()16 cli.OsExiter = func(code int) {}17 // Test cases18 var cases = []struct {19 args []string20 loginSource *models.LoginSource21 errMsg string22 }{23 // case 024 {25 args: []string{26 "ldap-test",27 "--name", "ldap (via Bind DN) source full",28 "--not-active",29 "--security-protocol", "ldaps",30 "--skip-tls-verify",31 "--host", "ldap-bind-server full",32 "--port", "9876",33 "--user-search-base", "ou=Users,dc=full-domain-bind,dc=org",34 "--user-filter", "(memberOf=cn=user-group,ou=example,dc=full-domain-bind,dc=org)",35 "--admin-filter", "(memberOf=cn=admin-group,ou=example,dc=full-domain-bind,dc=org)",36 "--restricted-filter", "(memberOf=cn=restricted-group,ou=example,dc=full-domain-bind,dc=org)",37 "--username-attribute", "uid-bind full",38 "--firstname-attribute", "givenName-bind full",39 "--surname-attribute", "sn-bind full",40 "--email-attribute", "mail-bind full",41 "--public-ssh-key-attribute", "publickey-bind full",42 "--bind-dn", "cn=readonly,dc=full-domain-bind,dc=org",43 "--bind-password", "secret-bind-full",44 "--attributes-in-bind",45 "--synchronize-users",46 "--page-size", "99",47 },48 loginSource: &models.LoginSource{49 Type: models.LoginLDAP,50 Name: "ldap (via Bind DN) source full",51 IsActived: false,52 IsSyncEnabled: true,53 Cfg: &models.LDAPConfig{54 Source: &ldap.Source{55 Name: "ldap (via Bind DN) source full",56 Host: "ldap-bind-server full",57 Port: 9876,58 SecurityProtocol: ldap.SecurityProtocol(1),59 SkipVerify: true,60 BindDN: "cn=readonly,dc=full-domain-bind,dc=org",61 BindPassword: "secret-bind-full",62 UserBase: "ou=Users,dc=full-domain-bind,dc=org",63 AttributeUsername: "uid-bind full",64 AttributeName: "givenName-bind full",65 AttributeSurname: "sn-bind full",66 AttributeMail: "mail-bind full",67 AttributesInBind: true,68 AttributeSSHPublicKey: "publickey-bind full",69 SearchPageSize: 99,70 Filter: "(memberOf=cn=user-group,ou=example,dc=full-domain-bind,dc=org)",71 AdminFilter: "(memberOf=cn=admin-group,ou=example,dc=full-domain-bind,dc=org)",72 RestrictedFilter: "(memberOf=cn=restricted-group,ou=example,dc=full-domain-bind,dc=org)",73 Enabled: true,74 },75 },76 },77 },78 // case 179 {80 args: []string{81 "ldap-test",82 "--name", "ldap (via Bind DN) source min",83 "--security-protocol", "unencrypted",84 "--host", "ldap-bind-server min",85 "--port", "1234",86 "--user-search-base", "ou=Users,dc=min-domain-bind,dc=org",87 "--user-filter", "(memberOf=cn=user-group,ou=example,dc=min-domain-bind,dc=org)",88 "--email-attribute", "mail-bind min",89 },90 loginSource: &models.LoginSource{91 Type: models.LoginLDAP,92 Name: "ldap (via Bind DN) source min",93 IsActived: true,94 Cfg: &models.LDAPConfig{95 Source: &ldap.Source{96 Name: "ldap (via Bind DN) source min",97 Host: "ldap-bind-server min",98 Port: 1234,99 SecurityProtocol: ldap.SecurityProtocol(0),100 UserBase: "ou=Users,dc=min-domain-bind,dc=org",101 AttributeMail: "mail-bind min",102 Filter: "(memberOf=cn=user-group,ou=example,dc=min-domain-bind,dc=org)",103 Enabled: true,104 },105 },106 },107 },108 // case 2109 {110 args: []string{111 "ldap-test",112 "--name", "ldap (via Bind DN) source",113 "--security-protocol", "zzzzz",114 "--host", "ldap-server",115 "--port", "1234",116 "--user-search-base", "ou=Users,dc=domain,dc=org",117 "--user-filter", "(memberOf=cn=user-group,ou=example,dc=domain,dc=org)",118 "--email-attribute", "mail",119 },120 errMsg: "Unknown security protocol name: zzzzz",121 },122 // case 3123 {124 args: []string{125 "ldap-test",126 "--security-protocol", "unencrypted",127 "--host", "ldap-server",128 "--port", "1234",129 "--user-search-base", "ou=Users,dc=domain,dc=org",130 "--user-filter", "(memberOf=cn=user-group,ou=example,dc=domain,dc=org)",131 "--email-attribute", "mail",132 },133 errMsg: "name is not set",134 },135 // case 4136 {137 args: []string{138 "ldap-test",139 "--name", "ldap (via Bind DN) source",140 "--host", "ldap-server",141 "--port", "1234",142 "--user-search-base", "ou=Users,dc=domain,dc=org",143 "--user-filter", "(memberOf=cn=user-group,ou=example,dc=domain,dc=org)",144 "--email-attribute", "mail",145 },146 errMsg: "security-protocol is not set",147 },148 // case 5149 {150 args: []string{151 "ldap-test",152 "--name", "ldap (via Bind DN) source",153 "--security-protocol", "unencrypted",154 "--port", "1234",155 "--user-search-base", "ou=Users,dc=domain,dc=org",156 "--user-filter", "(memberOf=cn=user-group,ou=example,dc=domain,dc=org)",157 "--email-attribute", "mail",158 },159 errMsg: "host is not set",160 },161 // case 6162 {163 args: []string{164 "ldap-test",165 "--name", "ldap (via Bind DN) source",166 "--security-protocol", "unencrypted",167 "--host", "ldap-server",168 "--user-search-base", "ou=Users,dc=domain,dc=org",169 "--user-filter", "(memberOf=cn=user-group,ou=example,dc=domain,dc=org)",170 "--email-attribute", "mail",171 },172 errMsg: "port is not set",173 },174 // case 7175 {176 args: []string{177 "ldap-test",178 "--name", "ldap (via Bind DN) source",179 "--security-protocol", "unencrypted",180 "--host", "ldap-server",181 "--port", "1234",182 "--user-search-base", "ou=Users,dc=domain,dc=org",183 "--email-attribute", "mail",184 },185 errMsg: "user-filter is not set",186 },187 // case 8188 {189 args: []string{190 "ldap-test",191 "--name", "ldap (via Bind DN) source",192 "--security-protocol", "unencrypted",193 "--host", "ldap-server",194 "--port", "1234",195 "--user-search-base", "ou=Users,dc=domain,dc=org",196 "--user-filter", "(memberOf=cn=user-group,ou=example,dc=domain,dc=org)",197 },198 errMsg: "email-attribute is not set",199 },200 }201 for n, c := range cases {202 // Mock functions.203 var createdLoginSource *models.LoginSource204 service := &authService{205 initDB: func() error {206 return nil207 },208 createLoginSource: func(loginSource *models.LoginSource) error {209 createdLoginSource = loginSource210 return nil211 },212 updateLoginSource: func(loginSource *models.LoginSource) error {213 assert.FailNow(t, "case %d: should not call updateLoginSource", n)214 return nil215 },216 getLoginSourceByID: func(id int64) (*models.LoginSource, error) {217 assert.FailNow(t, "case %d: should not call getLoginSourceByID", n)218 return nil, nil219 },220 }221 // Create a copy of command to test222 app := cli.NewApp()223 app.Flags = cmdAuthAddLdapBindDn.Flags224 app.Action = service.addLdapBindDn225 // Run it226 err := app.Run(c.args)227 if c.errMsg != "" {228 assert.EqualError(t, err, c.errMsg, "case %d: error should match", n)229 } else {230 assert.NoError(t, err, "case %d: should have no errors", n)231 assert.Equal(t, c.loginSource, createdLoginSource, "case %d: wrong loginSource", n)232 }233 }234}235func TestAddLdapSimpleAuth(t *testing.T) {236 // Mock cli functions to do not exit on error237 var osExiter = cli.OsExiter238 defer func() { cli.OsExiter = osExiter }()239 cli.OsExiter = func(code int) {}240 // Test cases241 var cases = []struct {242 args []string243 loginSource *models.LoginSource244 errMsg string245 }{246 // case 0247 {248 args: []string{249 "ldap-test",250 "--name", "ldap (simple auth) source full",251 "--not-active",252 "--security-protocol", "starttls",253 "--skip-tls-verify",254 "--host", "ldap-simple-server full",255 "--port", "987",256 "--user-search-base", "ou=Users,dc=full-domain-simple,dc=org",257 "--user-filter", "(&(objectClass=posixAccount)(full-simple-cn=%s))",258 "--admin-filter", "(memberOf=cn=admin-group,ou=example,dc=full-domain-simple,dc=org)",259 "--restricted-filter", "(memberOf=cn=restricted-group,ou=example,dc=full-domain-simple,dc=org)",260 "--username-attribute", "uid-simple full",261 "--firstname-attribute", "givenName-simple full",262 "--surname-attribute", "sn-simple full",263 "--email-attribute", "mail-simple full",264 "--public-ssh-key-attribute", "publickey-simple full",265 "--user-dn", "cn=%s,ou=Users,dc=full-domain-simple,dc=org",266 },267 loginSource: &models.LoginSource{268 Type: models.LoginDLDAP,269 Name: "ldap (simple auth) source full",270 IsActived: false,271 Cfg: &models.LDAPConfig{272 Source: &ldap.Source{273 Name: "ldap (simple auth) source full",274 Host: "ldap-simple-server full",275 Port: 987,276 SecurityProtocol: ldap.SecurityProtocol(2),277 SkipVerify: true,278 UserDN: "cn=%s,ou=Users,dc=full-domain-simple,dc=org",279 UserBase: "ou=Users,dc=full-domain-simple,dc=org",280 AttributeUsername: "uid-simple full",281 AttributeName: "givenName-simple full",282 AttributeSurname: "sn-simple full",283 AttributeMail: "mail-simple full",284 AttributeSSHPublicKey: "publickey-simple full",285 Filter: "(&(objectClass=posixAccount)(full-simple-cn=%s))",286 AdminFilter: "(memberOf=cn=admin-group,ou=example,dc=full-domain-simple,dc=org)",287 RestrictedFilter: "(memberOf=cn=restricted-group,ou=example,dc=full-domain-simple,dc=org)",288 Enabled: true,289 },290 },291 },292 },293 // case 1294 {295 args: []string{296 "ldap-test",297 "--name", "ldap (simple auth) source min",298 "--security-protocol", "unencrypted",299 "--host", "ldap-simple-server min",300 "--port", "123",301 "--user-filter", "(&(objectClass=posixAccount)(min-simple-cn=%s))",302 "--email-attribute", "mail-simple min",303 "--user-dn", "cn=%s,ou=Users,dc=min-domain-simple,dc=org",304 },305 loginSource: &models.LoginSource{306 Type: models.LoginDLDAP,307 Name: "ldap (simple auth) source min",308 IsActived: true,309 Cfg: &models.LDAPConfig{310 Source: &ldap.Source{311 Name: "ldap (simple auth) source min",312 Host: "ldap-simple-server min",313 Port: 123,314 SecurityProtocol: ldap.SecurityProtocol(0),315 UserDN: "cn=%s,ou=Users,dc=min-domain-simple,dc=org",316 AttributeMail: "mail-simple min",317 Filter: "(&(objectClass=posixAccount)(min-simple-cn=%s))",318 Enabled: true,319 },320 },321 },322 },323 // case 2324 {325 args: []string{326 "ldap-test",327 "--name", "ldap (simple auth) source",328 "--security-protocol", "zzzzz",329 "--host", "ldap-server",330 "--port", "123",331 "--user-filter", "(&(objectClass=posixAccount)(cn=%s))",332 "--email-attribute", "mail",333 "--user-dn", "cn=%s,ou=Users,dc=domain,dc=org",334 },335 errMsg: "Unknown security protocol name: zzzzz",336 },337 // case 3338 {339 args: []string{340 "ldap-test",341 "--security-protocol", "unencrypted",342 "--host", "ldap-server",343 "--port", "123",344 "--user-filter", "(&(objectClass=posixAccount)(cn=%s))",345 "--email-attribute", "mail",346 "--user-dn", "cn=%s,ou=Users,dc=domain,dc=org",347 },348 errMsg: "name is not set",349 },350 // case 4351 {352 args: []string{353 "ldap-test",354 "--name", "ldap (simple auth) source",355 "--host", "ldap-server",356 "--port", "123",357 "--user-filter", "(&(objectClass=posixAccount)(cn=%s))",358 "--email-attribute", "mail",359 "--user-dn", "cn=%s,ou=Users,dc=domain,dc=org",360 },361 errMsg: "security-protocol is not set",362 },363 // case 5364 {365 args: []string{366 "ldap-test",367 "--name", "ldap (simple auth) source",368 "--security-protocol", "unencrypted",369 "--port", "123",370 "--user-filter", "(&(objectClass=posixAccount)(cn=%s))",371 "--email-attribute", "mail",372 "--user-dn", "cn=%s,ou=Users,dc=domain,dc=org",373 },374 errMsg: "host is not set",375 },376 // case 6377 {378 args: []string{379 "ldap-test",380 "--name", "ldap (simple auth) source",381 "--security-protocol", "unencrypted",382 "--host", "ldap-server",383 "--user-filter", "(&(objectClass=posixAccount)(cn=%s))",384 "--email-attribute", "mail",385 "--user-dn", "cn=%s,ou=Users,dc=domain,dc=org",386 },387 errMsg: "port is not set",388 },389 // case 7390 {391 args: []string{392 "ldap-test",393 "--name", "ldap (simple auth) source",394 "--security-protocol", "unencrypted",395 "--host", "ldap-server",396 "--port", "123",397 "--email-attribute", "mail",398 "--user-dn", "cn=%s,ou=Users,dc=domain,dc=org",399 },400 errMsg: "user-filter is not set",401 },402 // case 8403 {404 args: []string{405 "ldap-test",406 "--name", "ldap (simple auth) source",407 "--security-protocol", "unencrypted",408 "--host", "ldap-server",409 "--port", "123",410 "--user-filter", "(&(objectClass=posixAccount)(cn=%s))",411 "--user-dn", "cn=%s,ou=Users,dc=domain,dc=org",412 },413 errMsg: "email-attribute is not set",414 },415 // case 9416 {417 args: []string{418 "ldap-test",419 "--name", "ldap (simple auth) source",420 "--security-protocol", "unencrypted",421 "--host", "ldap-server",422 "--port", "123",423 "--user-filter", "(&(objectClass=posixAccount)(cn=%s))",424 "--email-attribute", "mail",425 },426 errMsg: "user-dn is not set",427 },428 }429 for n, c := range cases {430 // Mock functions.431 var createdLoginSource *models.LoginSource432 service := &authService{433 initDB: func() error {434 return nil435 },436 createLoginSource: func(loginSource *models.LoginSource) error {437 createdLoginSource = loginSource438 return nil439 },440 updateLoginSource: func(loginSource *models.LoginSource) error {441 assert.FailNow(t, "case %d: should not call updateLoginSource", n)442 return nil443 },444 getLoginSourceByID: func(id int64) (*models.LoginSource, error) {445 assert.FailNow(t, "case %d: should not call getLoginSourceByID", n)446 return nil, nil447 },448 }449 // Create a copy of command to test450 app := cli.NewApp()451 app.Flags = cmdAuthAddLdapSimpleAuth.Flags452 app.Action = service.addLdapSimpleAuth453 // Run it454 err := app.Run(c.args)455 if c.errMsg != "" {456 assert.EqualError(t, err, c.errMsg, "case %d: error should match", n)457 } else {458 assert.NoError(t, err, "case %d: should have no errors", n)459 assert.Equal(t, c.loginSource, createdLoginSource, "case %d: wrong loginSource", n)460 }461 }462}463func TestUpdateLdapBindDn(t *testing.T) {464 // Mock cli functions to do not exit on error465 var osExiter = cli.OsExiter466 defer func() { cli.OsExiter = osExiter }()467 cli.OsExiter = func(code int) {}468 // Test cases469 var cases = []struct {470 args []string471 id int64472 existingLoginSource *models.LoginSource473 loginSource *models.LoginSource474 errMsg string475 }{476 // case 0477 {478 args: []string{479 "ldap-test",480 "--id", "23",481 "--name", "ldap (via Bind DN) source full",482 "--not-active",483 "--security-protocol", "LDAPS",484 "--skip-tls-verify",485 "--host", "ldap-bind-server full",486 "--port", "9876",487 "--user-search-base", "ou=Users,dc=full-domain-bind,dc=org",488 "--user-filter", "(memberOf=cn=user-group,ou=example,dc=full-domain-bind,dc=org)",489 "--admin-filter", "(memberOf=cn=admin-group,ou=example,dc=full-domain-bind,dc=org)",490 "--restricted-filter", "(memberOf=cn=restricted-group,ou=example,dc=full-domain-bind,dc=org)",491 "--username-attribute", "uid-bind full",492 "--firstname-attribute", "givenName-bind full",493 "--surname-attribute", "sn-bind full",494 "--email-attribute", "mail-bind full",495 "--public-ssh-key-attribute", "publickey-bind full",496 "--bind-dn", "cn=readonly,dc=full-domain-bind,dc=org",497 "--bind-password", "secret-bind-full",498 "--synchronize-users",499 "--page-size", "99",500 },501 id: 23,502 existingLoginSource: &models.LoginSource{503 Type: models.LoginLDAP,504 IsActived: true,505 Cfg: &models.LDAPConfig{506 Source: &ldap.Source{507 Enabled: true,508 },509 },510 },511 loginSource: &models.LoginSource{512 Type: models.LoginLDAP,513 Name: "ldap (via Bind DN) source full",514 IsActived: false,515 IsSyncEnabled: true,516 Cfg: &models.LDAPConfig{517 Source: &ldap.Source{518 Name: "ldap (via Bind DN) source full",519 Host: "ldap-bind-server full",520 Port: 9876,521 SecurityProtocol: ldap.SecurityProtocol(1),522 SkipVerify: true,523 BindDN: "cn=readonly,dc=full-domain-bind,dc=org",524 BindPassword: "secret-bind-full",525 UserBase: "ou=Users,dc=full-domain-bind,dc=org",526 AttributeUsername: "uid-bind full",527 AttributeName: "givenName-bind full",528 AttributeSurname: "sn-bind full",529 AttributeMail: "mail-bind full",530 AttributesInBind: false,531 AttributeSSHPublicKey: "publickey-bind full",532 SearchPageSize: 99,533 Filter: "(memberOf=cn=user-group,ou=example,dc=full-domain-bind,dc=org)",534 AdminFilter: "(memberOf=cn=admin-group,ou=example,dc=full-domain-bind,dc=org)",535 RestrictedFilter: "(memberOf=cn=restricted-group,ou=example,dc=full-domain-bind,dc=org)",536 Enabled: true,537 },538 },539 },540 },541 // case 1542 {543 args: []string{544 "ldap-test",545 "--id", "1",546 },547 loginSource: &models.LoginSource{548 Type: models.LoginLDAP,549 Cfg: &models.LDAPConfig{550 Source: &ldap.Source{},551 },552 },553 },554 // case 2555 {556 args: []string{557 "ldap-test",558 "--id", "1",559 "--name", "ldap (via Bind DN) source",560 },561 loginSource: &models.LoginSource{562 Type: models.LoginLDAP,563 Name: "ldap (via Bind DN) source",564 Cfg: &models.LDAPConfig{565 Source: &ldap.Source{566 Name: "ldap (via Bind DN) source",567 },568 },569 },570 },571 // case 3572 {573 args: []string{574 "ldap-test",575 "--id", "1",576 "--not-active",577 },578 existingLoginSource: &models.LoginSource{579 Type: models.LoginLDAP,580 IsActived: true,581 Cfg: &models.LDAPConfig{582 Source: &ldap.Source{},583 },584 },585 loginSource: &models.LoginSource{586 Type: models.LoginLDAP,587 IsActived: false,588 Cfg: &models.LDAPConfig{589 Source: &ldap.Source{},590 },591 },592 },593 // case 4594 {595 args: []string{596 "ldap-test",597 "--id", "1",598 "--security-protocol", "LDAPS",599 },600 loginSource: &models.LoginSource{601 Type: models.LoginLDAP,602 Cfg: &models.LDAPConfig{603 Source: &ldap.Source{604 SecurityProtocol: ldap.SecurityProtocol(1),605 },606 },607 },608 },609 // case 5610 {611 args: []string{612 "ldap-test",613 "--id", "1",614 "--skip-tls-verify",615 },616 loginSource: &models.LoginSource{617 Type: models.LoginLDAP,618 Cfg: &models.LDAPConfig{619 Source: &ldap.Source{620 SkipVerify: true,621 },622 },623 },624 },625 // case 6626 {627 args: []string{628 "ldap-test",629 "--id", "1",630 "--host", "ldap-server",631 },632 loginSource: &models.LoginSource{633 Type: models.LoginLDAP,634 Cfg: &models.LDAPConfig{635 Source: &ldap.Source{636 Host: "ldap-server",637 },638 },639 },640 },641 // case 7642 {643 args: []string{644 "ldap-test",645 "--id", "1",646 "--port", "389",647 },648 loginSource: &models.LoginSource{649 Type: models.LoginLDAP,650 Cfg: &models.LDAPConfig{651 Source: &ldap.Source{652 Port: 389,653 },654 },655 },656 },657 // case 8658 {659 args: []string{660 "ldap-test",661 "--id", "1",662 "--user-search-base", "ou=Users,dc=domain,dc=org",663 },664 loginSource: &models.LoginSource{665 Type: models.LoginLDAP,666 Cfg: &models.LDAPConfig{667 Source: &ldap.Source{668 UserBase: "ou=Users,dc=domain,dc=org",669 },670 },671 },672 },673 // case 9674 {675 args: []string{676 "ldap-test",677 "--id", "1",678 "--user-filter", "(memberOf=cn=user-group,ou=example,dc=domain,dc=org)",679 },680 loginSource: &models.LoginSource{681 Type: models.LoginLDAP,682 Cfg: &models.LDAPConfig{683 Source: &ldap.Source{684 Filter: "(memberOf=cn=user-group,ou=example,dc=domain,dc=org)",685 },686 },687 },688 },689 // case 10690 {691 args: []string{692 "ldap-test",693 "--id", "1",694 "--admin-filter", "(memberOf=cn=admin-group,ou=example,dc=domain,dc=org)",695 },696 loginSource: &models.LoginSource{697 Type: models.LoginLDAP,698 Cfg: &models.LDAPConfig{699 Source: &ldap.Source{700 AdminFilter: "(memberOf=cn=admin-group,ou=example,dc=domain,dc=org)",701 },702 },703 },704 },705 // case 11706 {707 args: []string{708 "ldap-test",709 "--id", "1",710 "--username-attribute", "uid",711 },712 loginSource: &models.LoginSource{713 Type: models.LoginLDAP,714 Cfg: &models.LDAPConfig{715 Source: &ldap.Source{716 AttributeUsername: "uid",717 },718 },719 },720 },721 // case 12722 {723 args: []string{724 "ldap-test",725 "--id", "1",726 "--firstname-attribute", "givenName",727 },728 loginSource: &models.LoginSource{729 Type: models.LoginLDAP,730 Cfg: &models.LDAPConfig{731 Source: &ldap.Source{732 AttributeName: "givenName",733 },734 },735 },736 },737 // case 13738 {739 args: []string{740 "ldap-test",741 "--id", "1",742 "--surname-attribute", "sn",743 },744 loginSource: &models.LoginSource{745 Type: models.LoginLDAP,746 Cfg: &models.LDAPConfig{747 Source: &ldap.Source{748 AttributeSurname: "sn",749 },750 },751 },752 },753 // case 14754 {755 args: []string{756 "ldap-test",757 "--id", "1",758 "--email-attribute", "mail",759 },760 loginSource: &models.LoginSource{761 Type: models.LoginLDAP,762 Cfg: &models.LDAPConfig{763 Source: &ldap.Source{764 AttributeMail: "mail",765 },766 },767 },768 },769 // case 15770 {771 args: []string{772 "ldap-test",773 "--id", "1",774 "--attributes-in-bind",775 },776 loginSource: &models.LoginSource{777 Type: models.LoginLDAP,778 Cfg: &models.LDAPConfig{779 Source: &ldap.Source{780 AttributesInBind: true,781 },782 },783 },784 },785 // case 16786 {787 args: []string{788 "ldap-test",789 "--id", "1",790 "--public-ssh-key-attribute", "publickey",791 },792 loginSource: &models.LoginSource{793 Type: models.LoginLDAP,794 Cfg: &models.LDAPConfig{795 Source: &ldap.Source{796 AttributeSSHPublicKey: "publickey",797 },798 },799 },800 },801 // case 17802 {803 args: []string{804 "ldap-test",805 "--id", "1",806 "--bind-dn", "cn=readonly,dc=domain,dc=org",807 },808 loginSource: &models.LoginSource{809 Type: models.LoginLDAP,810 Cfg: &models.LDAPConfig{811 Source: &ldap.Source{812 BindDN: "cn=readonly,dc=domain,dc=org",813 },814 },815 },816 },817 // case 18818 {819 args: []string{820 "ldap-test",821 "--id", "1",822 "--bind-password", "secret",823 },824 loginSource: &models.LoginSource{825 Type: models.LoginLDAP,826 Cfg: &models.LDAPConfig{827 Source: &ldap.Source{828 BindPassword: "secret",829 },830 },831 },832 },833 // case 19834 {835 args: []string{836 "ldap-test",837 "--id", "1",838 "--synchronize-users",839 },840 loginSource: &models.LoginSource{841 Type: models.LoginLDAP,842 IsSyncEnabled: true,843 Cfg: &models.LDAPConfig{844 Source: &ldap.Source{},845 },846 },847 },848 // case 20849 {850 args: []string{851 "ldap-test",852 "--id", "1",853 "--page-size", "12",854 },855 loginSource: &models.LoginSource{856 Type: models.LoginLDAP,857 Cfg: &models.LDAPConfig{858 Source: &ldap.Source{859 SearchPageSize: 12,860 },861 },862 },863 },864 // case 21865 {866 args: []string{867 "ldap-test",868 "--id", "1",869 "--security-protocol", "xxxxx",870 },871 errMsg: "Unknown security protocol name: xxxxx",872 },873 // case 22874 {875 args: []string{876 "ldap-test",877 },878 errMsg: "id is not set",879 },880 // case 23881 {882 args: []string{883 "ldap-test",884 "--id", "1",885 },886 existingLoginSource: &models.LoginSource{887 Type: models.LoginOAuth2,888 Cfg: &models.LDAPConfig{889 Source: &ldap.Source{},890 },891 },892 errMsg: "Invalid authentication type. expected: LDAP (via BindDN), actual: OAuth2",893 },894 }895 for n, c := range cases {896 // Mock functions.897 var updatedLoginSource *models.LoginSource898 service := &authService{899 initDB: func() error {900 return nil901 },902 createLoginSource: func(loginSource *models.LoginSource) error {903 assert.FailNow(t, "case %d: should not call createLoginSource", n)904 return nil905 },906 updateLoginSource: func(loginSource *models.LoginSource) error {907 updatedLoginSource = loginSource908 return nil909 },910 getLoginSourceByID: func(id int64) (*models.LoginSource, error) {911 if c.id != 0 {912 assert.Equal(t, c.id, id, "case %d: wrong id", n)913 }914 if c.existingLoginSource != nil {915 return c.existingLoginSource, nil916 }917 return &models.LoginSource{918 Type: models.LoginLDAP,919 Cfg: &models.LDAPConfig{920 Source: &ldap.Source{},921 },922 }, nil923 },924 }925 // Create a copy of command to test926 app := cli.NewApp()927 app.Flags = cmdAuthUpdateLdapBindDn.Flags928 app.Action = service.updateLdapBindDn929 // Run it930 err := app.Run(c.args)931 if c.errMsg != "" {932 assert.EqualError(t, err, c.errMsg, "case %d: error should match", n)933 } else {934 assert.NoError(t, err, "case %d: should have no errors", n)935 assert.Equal(t, c.loginSource, updatedLoginSource, "case %d: wrong loginSource", n)936 }937 }938}939func TestUpdateLdapSimpleAuth(t *testing.T) {940 // Mock cli functions to do not exit on error941 var osExiter = cli.OsExiter942 defer func() { cli.OsExiter = osExiter }()...

Full Screen

Full Screen

Bind

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 r := mux.NewRouter()4 r.HandleFunc("/bind", models.Bind).Methods("GET")5 http.ListenAndServe(":8080", r)6}7import (8type User struct {9}10func Bind(w http.ResponseWriter, r *http.Request) {11 u := User{}12 err := r.ParseForm()13 if err != nil {14 panic(err)15 }16 u.Name = r.FormValue("name")17 fmt.Fprintf(w, "User Name: %s", u.Name)18}19import (20func main() {21 r := mux.NewRouter()22 r.HandleFunc("/bind", models.Bind).Methods("GET")23 http.ListenAndServe(":8080", r)24}

Full Screen

Full Screen

Bind

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 m.Bind()4}5import (6type Models struct {7}8func (m *Models) Bind() {9 fmt.Println("Bind Method")10}11import (12func TestBind(t *testing.T) {13 m.Bind()14}15import (16func BenchmarkBind(b *testing.B) {17 for i := 0; i < b.N; i++ {18 m.Bind()19 }20}21import (22func ExampleBind() {23 m.Bind()24}25import (26func TestBind(t *testing.T) {27 m.Bind()28}29import (30func BenchmarkBind(b *testing.B) {31 for i := 0; i < b.N; i++ {32 m.Bind()33 }34}35import (36func ExampleBind() {37 m.Bind()38}39import (40func TestBind(t *testing.T) {41 m.Bind()42}43import (

Full Screen

Full Screen

Bind

Using AI Code Generation

copy

Full Screen

1import (2var decoder = schema.NewDecoder()3func init() {4 templates = template.Must(template.ParseGlob("templates/*.html"))5}6func main() {7 r := mux.NewRouter()8 r.HandleFunc("/", index)9 r.HandleFunc("/submit", submit)10 http.Handle("/", r)11 http.ListenAndServe(":8080", nil)12}13func index(w http.ResponseWriter, r *http.Request) {14 templates.ExecuteTemplate(w, "index.html", nil)15}16func submit(w http.ResponseWriter, r *http.Request) {17 r.ParseForm()18 decoder.IgnoreUnknownKeys(true)19 err := decoder.Decode(&user, r.PostForm)20 if err != nil {21 fmt.Println(err)22 }23 fmt.Println(user)24}25type User struct {26}27import (28var decoder = schema.NewDecoder()29func init() {30 templates = template.Must(template.ParseGlob("templates/*.html"))31}32func main() {33 r := mux.NewRouter()34 r.HandleFunc("/", index)35 r.HandleFunc("/submit", submit)36 http.Handle("/", r)37 http.ListenAndServe(":8080", nil)38}39func index(w http.ResponseWriter, r *http.Request) {40 templates.ExecuteTemplate(w, "index.html", nil)41}42func submit(w http.ResponseWriter, r *http.Request) {43 r.ParseForm()44 decoder.IgnoreUnknownKeys(true)45 err := decoder.Decode(&user, r.PostForm)46 if err != nil {47 fmt.Println(err)48 }49 fmt.Println(user)50}51type User struct {52}53import (54var decoder = schema.NewDecoder()55func init() {

Full Screen

Full Screen

Bind

Using AI Code Generation

copy

Full Screen

1func main() {2 m := models.NewModel()3 v := views.NewView(m)4 v.Start()5}6import (7func NewView(m *Model) *View {8 v := NewView(nil, 0)9 m.ConnectDataChanged(v.updateView)10}11func (v *View) updateView() {12 v.Label.SetText(v.Model.Data())13}14func (v *View) Start() {15 v.Show()16 widgets.QApplication_Exec()17}18type View struct {19 _ func() `constructor:"init"`20}21func (v *View) init() {22 v.SetMinimumSize2(300, 200)23 layout := widgets.NewQVBoxLayout()24 v.Label = widgets.NewQLabel(nil, 0)25 layout.AddWidget(v.Label, 0, 0)26 v.SetLayout(layout)27}28type Model struct {29}30func NewModel() *Model {31 m := NewModel(nil)

Full Screen

Full Screen

Bind

Using AI Code Generation

copy

Full Screen

1func (c *UserController) Post() {2 u := models.User{}3 c.ParseForm(&u)4 c.Ctx.WriteString(u.Name)5}6type User struct {7}8func main() {9 beego.AutoRouter(&controllers.UserController{})10 beego.Run()11}12What is the difference between c.ParseForm(&u) and c.ParseForm(u) ?

Full Screen

Full Screen

Bind

Using AI Code Generation

copy

Full Screen

1func main() {2}3func main() {4}5func main() {6}7import (8func main() {9}

Full Screen

Full Screen

Bind

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 s.Bind("Name", "John")5 s.Bind("Age", "21")6 fmt.Println(s.Name)7 fmt.Println(s.Age)8 m = make(map[string]string)9 s.BindMap(m)10 fmt.Println(s.Name)11 fmt.Println(s.Age)12}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Keploy automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful