mirror of https://github.com/bjdgyc/anylink.git
还原测试用例代码
This commit is contained in:
parent
ff129b072f
commit
77116ea854
|
@ -3,6 +3,7 @@ package dbdata
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/bjdgyc/anylink/pkg/utils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -42,33 +43,33 @@ func TestGetGroupNames(t *testing.T) {
|
||||||
err = SetGroup(&g6)
|
err = SetGroup(&g6)
|
||||||
ast.Nil(err)
|
ast.Nil(err)
|
||||||
|
|
||||||
// authData = map[string]interface{}{
|
authData = map[string]interface{}{
|
||||||
// "type": "ldap",
|
"type": "ldap",
|
||||||
// "ldap": map[string]interface{}{
|
"ldap": map[string]interface{}{
|
||||||
// "addr": "192.168.8.12:389",
|
"addr": "192.168.8.12:389",
|
||||||
// "tls": true,
|
"tls": true,
|
||||||
// "bind_name": "userfind@abc.com",
|
"bind_name": "userfind@abc.com",
|
||||||
// "bind_pwd": "afdbfdsafds",
|
"bind_pwd": "afdbfdsafds",
|
||||||
// "base_dn": "dc=abc,dc=com",
|
"base_dn": "dc=abc,dc=com",
|
||||||
// "object_class": "person",
|
"object_class": "person",
|
||||||
// "search_attr": "sAMAccountName",
|
"search_attr": "sAMAccountName",
|
||||||
// "member_of": "cn=vpn,cn=user,dc=abc,dc=com",
|
"member_of": "cn=vpn,cn=user,dc=abc,dc=com",
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
// g7 := Group{Name: "g7", ClientDns: []ValData{{Val: "114.114.114.114"}}, Auth: authData}
|
g7 := Group{Name: "g7", ClientDns: []ValData{{Val: "114.114.114.114"}}, Auth: authData}
|
||||||
// err = SetGroup(&g7)
|
err = SetGroup(&g7)
|
||||||
// ast.Nil(err)
|
ast.Nil(err)
|
||||||
|
|
||||||
// // 判断所有数据
|
// 判断所有数据
|
||||||
// gAll := []string{"g1", "g2", "g3", "g4", "g5", "g6", "g7"}
|
gAll := []string{"g1", "g2", "g3", "g4", "g5", "g6", "g7"}
|
||||||
// gs := GetGroupNames()
|
gs := GetGroupNames()
|
||||||
// for _, v := range gs {
|
for _, v := range gs {
|
||||||
// ast.Equal(true, utils.InArrStr(gAll, v))
|
ast.Equal(true, utils.InArrStr(gAll, v))
|
||||||
// }
|
}
|
||||||
|
|
||||||
// gni := GetGroupNamesIds()
|
gni := GetGroupNamesIds()
|
||||||
// for _, v := range gni {
|
for _, v := range gni {
|
||||||
// ast.NotEqual(0, v.Id)
|
ast.NotEqual(0, v.Id)
|
||||||
// ast.Equal(true, utils.InArrStr(gAll, v.Name))
|
ast.Equal(true, utils.InArrStr(gAll, v.Name))
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,87 +2,89 @@ package dbdata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCheckUser(t *testing.T) {
|
func TestCheckUser(t *testing.T) {
|
||||||
// ast := assert.New(t)
|
ast := assert.New(t)
|
||||||
|
|
||||||
// preIpData()
|
preIpData()
|
||||||
// defer closeIpdata()
|
defer closeIpdata()
|
||||||
|
|
||||||
// group := "group1"
|
group := "group1"
|
||||||
|
|
||||||
// // 添加一个组
|
// 添加一个组
|
||||||
// dns := []ValData{{Val: "114.114.114.114"}}
|
dns := []ValData{{Val: "114.114.114.114"}}
|
||||||
// route := []ValData{{Val: "192.168.1.0/24"}}
|
route := []ValData{{Val: "192.168.1.0/24"}}
|
||||||
// g := Group{Name: group, Status: 1, ClientDns: dns, RouteInclude: route}
|
g := Group{Name: group, Status: 1, ClientDns: dns, RouteInclude: route}
|
||||||
// err := SetGroup(&g)
|
err := SetGroup(&g)
|
||||||
// ast.Nil(err)
|
ast.Nil(err)
|
||||||
// // 判断 IpMask
|
// 判断 IpMask
|
||||||
// ast.Equal(g.RouteInclude[0].IpMask, "192.168.1.0/255.255.255.0")
|
ast.Equal(g.RouteInclude[0].IpMask, "192.168.1.0/255.255.255.0")
|
||||||
|
|
||||||
// // 添加一个用户
|
// 添加一个用户
|
||||||
// pincode := "a123456"
|
pincode := "a123456"
|
||||||
// u := User{Username: "aaa", PinCode: pincode, Groups: []string{group}, Status: 1}
|
u := User{Username: "aaa", PinCode: pincode, Groups: []string{group}, Status: 1}
|
||||||
// err = SetUser(&u)
|
err = SetUser(&u)
|
||||||
|
ast.Nil(err)
|
||||||
|
|
||||||
|
// 验证 PinCode + OtpSecret
|
||||||
|
// totp := gotp.NewDefaultTOTP(u.OtpSecret)
|
||||||
|
// secret := totp.Now()
|
||||||
|
// err = CheckUser("aaa", u.PinCode+secret, group)
|
||||||
// ast.Nil(err)
|
// ast.Nil(err)
|
||||||
|
|
||||||
// // 验证 PinCode + OtpSecret
|
// 单独验证密码
|
||||||
// // totp := gotp.NewDefaultTOTP(u.OtpSecret)
|
u.DisableOtp = true
|
||||||
// // secret := totp.Now()
|
_ = SetUser(&u)
|
||||||
// // err = CheckUser("aaa", u.PinCode+secret, group)
|
err = CheckUser("aaa", pincode, group)
|
||||||
// // ast.Nil(err)
|
ast.Nil(err)
|
||||||
|
|
||||||
// // 单独验证密码
|
// 添加一个radius组
|
||||||
// u.DisableOtp = true
|
group2 := "group2"
|
||||||
// _ = SetUser(&u)
|
authData := map[string]interface{}{
|
||||||
// err = CheckUser("aaa", pincode, group)
|
"type": "radius",
|
||||||
// ast.Nil(err)
|
"radius": map[string]string{
|
||||||
|
"addr": "192.168.1.12:1044",
|
||||||
// // 添加一个radius组
|
"secret": "43214132",
|
||||||
// group2 := "group2"
|
},
|
||||||
// authData := map[string]interface{}{
|
}
|
||||||
// "type": "radius",
|
g2 := Group{Name: group2, Status: 1, ClientDns: dns, RouteInclude: route, Auth: authData}
|
||||||
// "radius": map[string]string{
|
err = SetGroup(&g2)
|
||||||
// "addr": "192.168.1.12:1044",
|
ast.Nil(err)
|
||||||
// "secret": "43214132",
|
err = CheckUser("aaa", "bbbbbbb", group2)
|
||||||
// },
|
if ast.NotNil(err) {
|
||||||
// }
|
ast.Equal("aaa Radius服务器连接异常, 请检测服务器和端口", err.Error())
|
||||||
// g2 := Group{Name: group2, Status: 1, ClientDns: dns, RouteInclude: route, Auth: authData}
|
}
|
||||||
// err = SetGroup(&g2)
|
// 添加用户策略
|
||||||
// ast.Nil(err)
|
dns2 := []ValData{{Val: "8.8.8.8"}}
|
||||||
// err = CheckUser("aaa", "bbbbbbb", group2)
|
route2 := []ValData{{Val: "192.168.2.0/24"}}
|
||||||
// if ast.NotNil(err) {
|
p1 := Policy{Username: "aaa", Status: 1, ClientDns: dns2, RouteInclude: route2}
|
||||||
// ast.Equal("aaa Radius服务器连接异常, 请检测服务器和端口", err.Error())
|
err = SetPolicy(&p1)
|
||||||
// }
|
ast.Nil(err)
|
||||||
// // 添加用户策略
|
err = CheckUser("aaa", pincode, group)
|
||||||
// dns2 := []ValData{{Val: "8.8.8.8"}}
|
ast.Nil(err)
|
||||||
// route2 := []ValData{{Val: "192.168.2.0/24"}}
|
// 添加一个ldap组
|
||||||
// p1 := Policy{Username: "aaa", Status: 1, ClientDns: dns2, RouteInclude: route2}
|
group3 := "group3"
|
||||||
// err = SetPolicy(&p1)
|
authData = map[string]interface{}{
|
||||||
// ast.Nil(err)
|
"type": "ldap",
|
||||||
// err = CheckUser("aaa", pincode, group)
|
"ldap": map[string]interface{}{
|
||||||
// ast.Nil(err)
|
"addr": "192.168.8.12:389",
|
||||||
// // 添加一个ldap组
|
"tls": true,
|
||||||
// group3 := "group3"
|
"bind_name": "userfind@abc.com",
|
||||||
// authData = map[string]interface{}{
|
"bind_pwd": "afdbfdsafds",
|
||||||
// "type": "ldap",
|
"base_dn": "dc=abc,dc=com",
|
||||||
// "ldap": map[string]interface{}{
|
"object_class": "person",
|
||||||
// "addr": "192.168.8.12:389",
|
"search_attr": "sAMAccountName",
|
||||||
// "tls": true,
|
"member_of": "cn=vpn,cn=user,dc=abc,dc=com",
|
||||||
// "bind_name": "userfind@abc.com",
|
},
|
||||||
// "bind_pwd": "afdbfdsafds",
|
}
|
||||||
// "base_dn": "dc=abc,dc=com",
|
g3 := Group{Name: group3, Status: 1, ClientDns: dns, RouteInclude: route, Auth: authData}
|
||||||
// "object_class": "person",
|
err = SetGroup(&g3)
|
||||||
// "search_attr": "sAMAccountName",
|
ast.Nil(err)
|
||||||
// "member_of": "cn=vpn,cn=user,dc=abc,dc=com",
|
err = CheckUser("aaa", "bbbbbbb", group3)
|
||||||
// },
|
if ast.NotNil(err) {
|
||||||
// }
|
ast.Equal("aaa LDAP服务器连接异常, 请检测服务器和端口", err.Error())
|
||||||
// g3 := Group{Name: group3, Status: 1, ClientDns: dns, RouteInclude: route, Auth: authData}
|
}
|
||||||
// err = SetGroup(&g3)
|
|
||||||
// ast.Nil(err)
|
|
||||||
// err = CheckUser("aaa", "bbbbbbb", group3)
|
|
||||||
// if ast.NotNil(err) {
|
|
||||||
// ast.Equal("aaa LDAP服务器连接异常, 请检测服务器和端口", err.Error())
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue