<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          ldap-test-tool輕量級 ldap 測試工具

          聯(lián)合創(chuàng)作 · 2023-10-01 17:03

          ldap-test-tool

          一個輕量級的 ldap 測試工具

          支持:

          • ldap 認證

          • ldap 查詢(默認基于用戶)

          • 自定義 filter 的 ldap 查詢

          • 多用戶的批量 ldap 認證

          • 多用戶的批量 ldap 查詢

          • 支持批量查詢結(jié)果輸出到 csv

          • REST API

          編譯

          go get ./...
          go build

          release

          可以直接下載編譯好的 release 版本

          提供 win64 和 linux64 兩個平臺的可執(zhí)行文件

          https://github.com/shanghai-edu/ldap-test-tool/releases/

          配置文件

          默認配置文件為目錄下的 cfg.json,也可以使用 -c 或 --config 來加載自定義的配置文件。

          openldap 配置示例

          {
              "ldap": {
                  "addr": "ldap.example.org:389",
                  "baseDn": "dc=example,dc=org",
                  "bindDn": "cn=manager,dc=example,dc=org",
                  "bindPass": "password",
                  "authFilter": "(&(uid=%s))",
                  "attributes": ["uid", "cn", "mail"],
                  "tls":        false,
                  "startTLS":   false
              },
              "http": {
                  "listen": "0.0.0.0:8888"
              }
          }

          AD 配置示例

          {
              "ldap": {
                  "addr": "ad.example.org:389",
                  "baseDn": "dc=example,dc=org",
                  "bindDn": "[email protected]",
                  "bindPass": "password",
                  "authFilter": "(&(sAMAccountName=%s))",
                  "attributes": ["sAMAccountName", "displayName", "mail"],
                  "tls":        false,
                  "startTLS":   false
              },
              "http": {
                  "listen": "0.0.0.0:8888"
              }
          }

          命令體系

          命令行部分使用 cobra 框架,可以使用 help 命令查看命令的使用方式

          # ./ldap-test-tool help
          ldap-test-tool is a simple tool for ldap test
          build by shanghai-edu.
          Complete documentation is available at github.com/shanghai-edu/ldap-test-tool
          
          Usage:
            ldap-test-tool [flags]
            ldap-test-tool [command]
          
          Available Commands:
            auth        Auth Test
            help        Help about any command
            http        Enable a http server for ldap-test-tool
            search      Search Test
            version     Print the version number of ldap-test-tool
          
          Flags:
            -c, --config string   load config file. default cfg.json (default "cfg.json")
            -h, --help            help for ldap-test-tool
          
          Use "ldap-test-tool [command] --help" for more information about a command.

          認證

          ./ldap-test-tool auth -h
          Auth Test
          
          Usage:
            ldap-test-tool auth [flags]
            ldap-test-tool auth [command]
          
          Available Commands:
            multi       Multi Auth Test
            single      Single Auth Test
          
          Flags:
            -h, --help   help for auth
          
          Global Flags:
            -c, --config string   load config file. default cfg.json (default "cfg.json")
          
          Use "ldap-test-tool auth [command] --help" for more information about a command.

          單用戶測試

          命令行說明

          Single Auth Test
          
          Usage:
            ldap-test-tool auth single [username] [password] [flags]
          
          Flags:
            -h, --help   help for single
          
          Global Flags:
            -c, --config string   load config file. default cfg.json (default "cfg.json")

          示例

          ./ldap-test-tool auth single qfeng 123456
          LDAP Auth Start 
          ==================================
          
          qfeng auth test successed 
          
          ==================================
          LDAP Auth Finished, Time Usage 47.821884ms

          批量測試

          命令行說明

          # ./ldap-test-tool auth multi -h
          Multi Auth Test
          
          Usage:
            ldap-test-tool auth multi [filename] [flags]
          
          Flags:
            -h, --help   help for multi
          
          Global Flags:
            -c, --config string   load config file. default cfg.json (default "cfg.json")

          示例

          # cat authusers.txt 
          qfeng,123456
          qfengtest,111111

          用戶名和密碼以逗號分隔(csv風格) authusers.txt 中有兩個用戶,密碼正確的 qfeng 和密碼錯誤的 qfengtest

          # ./ldap-test-tool auth multi authusers.txt 
          LDAP Multi Auth Start 
          ==================================
          
          Successed count 1 
          Failed count 1 
          Failed users:
           -- User: qfengtest , Msg: Cannot find such user 
          
          ==================================
          LDAP Multi Auth Finished, Time Usage 49.582994ms

          查詢

          # ./ldap-test-tool search -h
          Search Test
          
          Usage:
            ldap-test-tool search [flags]
            ldap-test-tool search [command]
          
          Available Commands:
            filter      Search By Filter
            multi       Search Multi Users
            user        Search Single User
          
          Flags:
            -h, --help   help for search
          
          Global Flags:
            -c, --config string   load config file. default cfg.json (default "cfg.json")
          
          Use "ldap-test-tool search [command] --help" for more information about a command.
          [root@wiki-qfeng ldap-test-tool]#

          單用戶查詢

          命令行說明

          # ./ldap-test-tool search user -h
          Search Single User
          
          Usage:
            ldap-test-tool search user [username] [flags]
          
          Flags:
            -h, --help   help for user
          
          Global Flags:
            -c, --config string   load config file. default cfg.json (default "cfg.json")
          [root@wiki-qfeng ldap-test-tool]#

          示例

          # ./ldap-test-tool search user qfeng
          LDAP Search Start 
          ==================================
          
          
          DN: uid=qfeng,ou=people,dc=example,dc=org
          Attributes:
           -- uid  : qfeng 
           -- cn   : 馮騏測試 
           -- mail : [email protected]
          
          
          ==================================
          LDAP Search Finished, Time Usage 44.711268ms

          PS: 如果屬性有多值,將以 ; 分割

          LDAP Filter 查詢

          # ./ldap-test-tool search filter -h
          Search By Filter
          
          Usage:
            ldap-test-tool search filter [searchFilter] [flags]
          
          Flags:
            -h, --help   help for filter
          
          Global Flags:
            -c, --config string   load config file. default cfg.json (default "cfg.json")

          示例

          # ./ldap-test-tool search filter "(cn=*測試)"
          LDAP Search By Filter Start 
          ==================================
          
          
          DN: uid=test1,ou=people,dc=example,dc=org
          Attributes:
           -- uid  : test1 
           -- cn   : 一號測試 
           -- mail : [email protected] 
          
          
          DN: uid=test2,ou=people,dc=example,dc=org
          Attributes:
           -- uid  : test2 
           -- cn   : 二號測試 
           -- mail : [email protected] 
          
          
          DN: uid=test3,ou=people,dc=example,dc=org
          Attributes:
           -- uid  : test3
           -- cn   : 三號測試 
           -- mail : [email protected] 
          
          results count  3
          
          ==================================
          LDAP Search By Filter Finished, Time Usage 46.071833ms

          批量查詢測試

          命令行說明

          # ./ldap-test-tool search multi -h
          Search Multi Users
          
          Usage:
            ldap-test-tool search multi [filename] [flags]
          
          Flags:
            -f, --file   output search to users.csv, failed search to failed.csv
            -h, --help   help for multi
          
          Global Flags:
            -c, --config string   load config file. default cfg.json (default "cfg.json")

          示例

          # cat searchusers.txt 
          qfeng
          qfengtest
          nofounduser

          searchuser.txt 中有三個用戶,其中 nofounduser 是不存在的用戶

          # ldap-test-tool.exe search multi .\searchusers.txt
          LDAP Multi Search Start
          ==================================
          
          Successed users:
          
          DN: uid=qfeng,ou=people,dc=example,dc=org
          Attributes:
           -- uid  : qfeng
           -- cn   : 馮騏
           -- mail : [email protected]
          
          
          DN: uid=qfengtest,ou=people,dc=example,dc=org
          Attributes:
           -- uid  : qfengtest
           -- cn   : 馮騏測試
           -- mail : [email protected]
          
          nofounduser : Cannot find such user
          
          Successed count 2
          Failed count 1
          
          ==================================
          LDAP Multi Search Finished, Time Usage 134.744ms

          當使用 -f 選項時,查詢的結(jié)果將輸出到 csv 中。csv 將以配置文件中 attributes 的屬性作為 title。因此當使用 -f 選項時,attributes 不得為空。

          # ./ldap-test-tool search multi searchusers.txt -f
          LDAP Multi Search Start 
          ==================================
          
          OutPut to csv successed
          
          ==================================
          LDAP Multi Search Finished, Time Usage 88.756956ms 
          
          # ls | grep csv
          failed.csv
          users.csv

          HTTP API

          HTTP API 部分使用 beego 框架 使用如下命令開啟 HTTP API

          # ldap-test-tool.exe http
          2018/03/12 14:30:25 [I] http server Running on http://0.0.0.0:8888

          健康狀態(tài)

          檢測 ldap 健康狀態(tài)

          # curl http://127.0.0.1:8888/api/v1/ldap/health   
          {
            "msg": "ok",
            "success": true
          }

          查詢用戶

          查詢單個用戶信息

          # curl  http://127.0.0.1:8888/api/v1/ldap/search/user/qfeng
          {
            "user": {
              "dn": "uid=qfeng,ou=people,dc=example,dc=org",
              "attributes": {
                "cn": [
                  "馮騏"
                ],
                "mail": [
                  "qfeng"
                ],
                "uid": [
                  "qfeng"
                ]
              }
            },
            "success": true
          }

          Filter 查詢

          根據(jù) LDAP Filter 查詢

          # curl  http://127.0.0.1:8888/api/v1/ldap/search/filter/\(cn=*測試\)
          {
            "results": [
              {
                "dn": "uid=test1,ou=people,dc=example,dc=org",
                "attributes": {
                  "cn": [
                    "一號測試"
                  ],
                  "mail": [
                    "[email protected]"
                  ],
                  "uid": [
                    "test1"
                  ]
                }
              },
              {
                "dn": "uid=test2,ou=people,dc=example,dc=org",
                "attributes": {
                  "cn": [
                    "二號測試"
                  ],
                  "mail": [
                    "[email protected]"
                  ],
                  "uid": [
                    "test2"
                  ]
                }
              },
              {
                "dn": "uid=test3,ou=people,dc=example,dc=org",
                "attributes": {
                  "cn": [
                    "三號測試"
                  ],
                  "mail": [
                    "[email protected]"
                  ],
                  "uid": [
                    "test3"
                  ]
                }
              },
            ],
            "success": true
          }

          多用戶查詢

          同時查詢多個用戶,以 application/json 方式發(fā)送請求數(shù)據(jù),請求數(shù)據(jù)示例

          ["qfeng","qfengtest","nofounduser"]

          curl 示例

          # curl -X POST  -H 'Content-Type:application/json' -d '["qfeng","qfengtest","nofounduser"]' http://127.0.0.1:8888/api/v1/ldap/search/multi
          {
            "success": true,
            "result": {
              "successed": 2,
              "failed": 1,
              "users": [
                {
                  "dn": "uid=qfeng,ou=people,dc=example,dc=org",
                  "attributes": {
                    "cn": [
                      "馮騏"
                    ],
                    "mail": [
                      "[email protected]"
                    ],
                    "uid": [
                      "qfeng"
                    ]
                  }
                },
                {
                  "dn": "uid=qfengtest,ou=people,dc=example,dc=org",
                  "attributes": {
                    "cn": [
                      "馮騏測試"
                    ],
                    "mail": [
                      "[email protected]"
                    ],
                    "uid": [
                      "qfengtest"
                    ]
                  }
                }
              ],
              "failed_messages": [
                {
                  "username": "nofounduser",
                  "message": "Cannot find such user"
                }
              ]
            }
          }

          認證

          單用戶認證

          單個用戶認證測試,以 application/json 方式發(fā)送請求數(shù)據(jù),請求數(shù)據(jù)示例

          {
          	"username": "qfeng",
          	"password": "123456"
          }

          curl 示例

          # curl -X POST  -H 'Content-Type:application/json' -d '{"username":"qfeng","password":"123456"}' http://127.0.0.1:8888/api/v1/ldap/auth/single
          {
            "msg": "user 20150073 Auth Successed",
            "success": true
          }

          多用戶認證

          同時發(fā)起多個用戶認證測試,以 application/json 方式發(fā)送請求數(shù)據(jù),請求數(shù)據(jù)示例

          [{
          	"username": "qfeng",
          	"password": "123456"
          }, {
          	"username": "qfengtest",
          	"password": "1111111"
          }]

          curl 示例

          # curl -X POST  -H 'Content-Type:application/json' -d '[{"username":"qfeng","password":"123456"},{"username":"qfengtest","password":"1111111"}]' http://127.0.0.1:8888/api/v1/ldap/auth/multi
          {
            "success": true,
            "result": {
              "successed": 1,
              "failed": 1,
              "failed_messages": [
                {
                  "username": "qfengtest",
                  "message": "LDAP Result Code 49 \"Invalid Credentials\": "
                }
              ]
            }
          }

          LICENSE

          Apache License 2.0

          瀏覽 26
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  久久影院国产 | 国产激情视频区 | 国产传媒天美果冻精品亚洲一区二区三区直播 | 人人草人人摸人人看 | 精品久久伊人网 |