commit
4ffc9f8919
@ -0,0 +1,4 @@
|
|||||||
|
.devcontainer
|
||||||
|
components
|
||||||
|
logs
|
||||||
|
|
@ -1,146 +1,147 @@
|
|||||||
# The class cannot be named by Pascal or camel case.
|
|
||||||
# If it is not used, the corresponding structure will not be set,
|
# The class cannot be named by Pascal or camel case.
|
||||||
# and it will not be read naturally.
|
# If it is not used, the corresponding structure will not be set,
|
||||||
serverversion: 1.0.0
|
# and it will not be read naturally.
|
||||||
#---------------Infrastructure configuration---------------------#
|
serverversion: 1.0.0
|
||||||
etcd:
|
#---------------Infrastructure configuration---------------------#
|
||||||
etcdSchema: openIM
|
etcd:
|
||||||
etcdAddr: [ 127.0.0.1:2379 ]
|
etcdSchema: openIM
|
||||||
|
etcdAddr: [ 127.0.0.1:2379 ]
|
||||||
mysql:
|
|
||||||
dbMysqlAddress: [ 127.0.0.1:3306 ]
|
mysql:
|
||||||
dbMysqlUserName: root
|
dbMysqlAddress: [ 127.0.0.1:3306 ]
|
||||||
dbMysqlPassword: openIM
|
dbMysqlUserName: root
|
||||||
dbMysqlDatabaseName: openIM
|
dbMysqlPassword: openIM
|
||||||
dbTableName: eMsg
|
dbMysqlDatabaseName: openIM
|
||||||
dbMsgTableNum: 1
|
dbTableName: eMsg
|
||||||
dbMaxOpenConns: 20
|
dbMsgTableNum: 1
|
||||||
dbMaxIdleConns: 10
|
dbMaxOpenConns: 20
|
||||||
dbMaxLifeTime: 120
|
dbMaxIdleConns: 10
|
||||||
|
dbMaxLifeTime: 120
|
||||||
mongo:
|
|
||||||
dbAddress: [ 127.0.0.1:27017 ]
|
mongo:
|
||||||
dbDirect: false
|
dbAddress: [ 127.0.0.1:27017 ]
|
||||||
dbTimeout: 10
|
dbDirect: false
|
||||||
dbDatabase: openIM
|
dbTimeout: 10
|
||||||
dbSource: admin
|
dbDatabase: openIM
|
||||||
dbUserName:
|
dbSource: admin
|
||||||
dbPassword:
|
dbUserName:
|
||||||
dbMaxPoolSize: 20
|
dbPassword:
|
||||||
dbRetainChatRecords: 7
|
dbMaxPoolSize: 20
|
||||||
|
dbRetainChatRecords: 7
|
||||||
redis:
|
|
||||||
dbAddress: 127.0.0.1:6379
|
redis:
|
||||||
dbMaxIdle: 128
|
dbAddress: 127.0.0.1:6379
|
||||||
dbMaxActive: 0
|
dbMaxIdle: 128
|
||||||
dbIdleTimeout: 120
|
dbMaxActive: 0
|
||||||
dbPassWord: openIM
|
dbIdleTimeout: 120
|
||||||
|
dbPassWord: openIM
|
||||||
kafka:
|
|
||||||
ws2mschat:
|
kafka:
|
||||||
addr: [ 127.0.0.1:9092 ]
|
ws2mschat:
|
||||||
topic: "ws2ms_chat"
|
addr: [ 127.0.0.1:9092 ]
|
||||||
ms2pschat:
|
topic: "ws2ms_chat"
|
||||||
addr: [ 127.0.0.1:9092 ]
|
ms2pschat:
|
||||||
topic: "ms2ps_chat"
|
addr: [ 127.0.0.1:9092 ]
|
||||||
consumergroupid:
|
topic: "ms2ps_chat"
|
||||||
msgToMongo: mongo
|
consumergroupid:
|
||||||
msgToMySql: mysql
|
msgToMongo: mongo
|
||||||
msgToPush: push
|
msgToMySql: mysql
|
||||||
|
msgToPush: push
|
||||||
|
|
||||||
|
|
||||||
#---------------Internal service configuration---------------------#
|
|
||||||
|
#---------------Internal service configuration---------------------#
|
||||||
# The service ip default is empty,
|
|
||||||
# automatically obtain the machine's valid network card ip as the service ip,
|
# The service ip default is empty,
|
||||||
# otherwise the configuration ip is preferred
|
# automatically obtain the machine's valid network card ip as the service ip,
|
||||||
serverip:
|
# otherwise the configuration ip is preferred
|
||||||
|
serverip:
|
||||||
api:
|
|
||||||
openImApiPort: [ 10000 ]
|
api:
|
||||||
sdk:
|
openImApiPort: [ 10000 ]
|
||||||
openImSdkWsPort: [ 30000 ]
|
sdk:
|
||||||
|
openImSdkWsPort: [ 30000 ]
|
||||||
credential:
|
|
||||||
tencent:
|
credential:
|
||||||
appID: 1302656840
|
tencent:
|
||||||
region: ap-chengdu
|
appID: 1302656840
|
||||||
bucket: echat-1302656840
|
region: ap-chengdu
|
||||||
secretID: AKIDGNYVChzIQinu7QEgtNp0hnNgqcV8vZTC
|
bucket: echat-1302656840
|
||||||
secretKey: kz15vW83qM6dBUWIq681eBZA0c0vlIbe
|
secretID: AKIDGNYVChzIQinu7QEgtNp0hnNgqcV8vZTC
|
||||||
|
secretKey: kz15vW83qM6dBUWIq681eBZA0c0vlIbe
|
||||||
|
|
||||||
rpcport:
|
|
||||||
openImUserPort: [ 10100 ]
|
rpcport:
|
||||||
openImFriendPort: [ 10200 ]
|
openImUserPort: [ 10100 ]
|
||||||
openImOfflineMessagePort: [ 10300 ]
|
openImFriendPort: [ 10200 ]
|
||||||
openImOnlineRelayPort: [ 10400 ]
|
openImOfflineMessagePort: [ 10300 ]
|
||||||
openImGroupPort: [ 10500 ]
|
openImOnlineRelayPort: [ 10400 ]
|
||||||
openImAuthPort: [ 10600 ]
|
openImGroupPort: [ 10500 ]
|
||||||
openImPushPort: [ 10700 ]
|
openImAuthPort: [ 10600 ]
|
||||||
|
openImPushPort: [ 10700 ]
|
||||||
|
|
||||||
rpcregistername:
|
|
||||||
openImUserName: User
|
rpcregistername:
|
||||||
openImFriendName: Friend
|
openImUserName: User
|
||||||
openImOfflineMessageName: OfflineMessage
|
openImFriendName: Friend
|
||||||
openImPushName: Push
|
openImOfflineMessageName: OfflineMessage
|
||||||
openImOnlineMessageRelayName: OnlineMessageRelay
|
openImPushName: Push
|
||||||
openImGroupName: Group
|
openImOnlineMessageRelayName: OnlineMessageRelay
|
||||||
openImAuthName: Auth
|
openImGroupName: Group
|
||||||
|
openImAuthName: Auth
|
||||||
log:
|
|
||||||
storageLocation: ../logs/
|
log:
|
||||||
rotationTime: 24
|
storageLocation: ../logs/
|
||||||
remainRotationCount: 5
|
rotationTime: 24
|
||||||
remainLogLevel: 6
|
remainRotationCount: 5
|
||||||
elasticSearchSwitch: false
|
remainLogLevel: 6
|
||||||
elasticSearchAddr: [ 127.0.0.1:9201 ]
|
elasticSearchSwitch: false
|
||||||
elasticSearchUser: ""
|
elasticSearchAddr: [ 127.0.0.1:9201 ]
|
||||||
elasticSearchPassword: ""
|
elasticSearchUser: ""
|
||||||
|
elasticSearchPassword: ""
|
||||||
modulename:
|
|
||||||
longConnSvrName: msg_gateway
|
modulename:
|
||||||
msgTransferName: msg_transfer
|
longConnSvrName: msg_gateway
|
||||||
pushName: push
|
msgTransferName: msg_transfer
|
||||||
|
pushName: push
|
||||||
longconnsvr:
|
|
||||||
openImWsPort: [ 17778 ]
|
longconnsvr:
|
||||||
websocketMaxConnNum: 10000
|
openImWsPort: [ 17778 ]
|
||||||
websocketMaxMsgLen: 4096
|
websocketMaxConnNum: 10000
|
||||||
websocketTimeOut: 10
|
websocketMaxMsgLen: 4096
|
||||||
|
websocketTimeOut: 10
|
||||||
push:
|
|
||||||
tpns:
|
push:
|
||||||
ios:
|
tpns:
|
||||||
accessID: 1600018281
|
ios:
|
||||||
secretKey: 3cd68a77a95b89e5089a1aca523f318f
|
accessID: 1600018281
|
||||||
android:
|
secretKey: 3cd68a77a95b89e5089a1aca523f318f
|
||||||
accessID: 111
|
android:
|
||||||
secretKey: 111
|
accessID: 111
|
||||||
jpns:
|
secretKey: 111
|
||||||
appKey: 2783339cee4de379cc798fe1
|
jpns:
|
||||||
masterSecret: 66e5f309e032c68cc668c28a
|
appKey: 2783339cee4de379cc798fe1
|
||||||
pushUrl: "https://api.jpush.cn/v3/push"
|
masterSecret: 66e5f309e032c68cc668c28a
|
||||||
manager:
|
pushUrl: "https://api.jpush.cn/v3/push"
|
||||||
appManagerUid: ["openIM123456","openIM654321"]
|
manager:
|
||||||
secrets: ["openIM1","openIM2"]
|
appManagerUid: ["openIM123456","openIM654321"]
|
||||||
|
secrets: ["openIM1","openIM2"]
|
||||||
secret: tuoyun
|
|
||||||
|
secret: tuoyun
|
||||||
multiloginpolicy:
|
|
||||||
onlyOneTerminalAccess: false
|
multiloginpolicy:
|
||||||
mobileAndPCTerminalAccessButOtherTerminalKickEachOther: true
|
onlyOneTerminalAccess: false
|
||||||
allTerminalAccess: false
|
mobileAndPCTerminalAccessButOtherTerminalKickEachOther: true
|
||||||
|
allTerminalAccess: false
|
||||||
#token config
|
|
||||||
tokenpolicy:
|
#token config
|
||||||
accessSecret: "open_im_server"
|
tokenpolicy:
|
||||||
# Token effective time seconds as a unit
|
accessSecret: "open_im_server"
|
||||||
#Seven days 7*24*60*60
|
# Token effective time seconds as a unit
|
||||||
accessExpire: 604800
|
#Seven days 7*24*60*60
|
||||||
|
accessExpire: 604800
|
||||||
messagecallback:
|
|
||||||
callbackSwitch: false
|
messagecallback:
|
||||||
|
callbackSwitch: false
|
||||||
callbackUrl: "http://www.xxx.com/msg/judge"
|
callbackUrl: "http://www.xxx.com/msg/judge"
|
@ -0,0 +1,12 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestServerIP(t *testing.T) {
|
||||||
|
if net.ParseIP(ServerIP) == nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"Open_IM/src/common/config"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_BuildClaims(t *testing.T) {
|
||||||
|
uid := "1"
|
||||||
|
platform := "PC"
|
||||||
|
ttl := int64(-1)
|
||||||
|
claim := BuildClaims(uid, platform, ttl)
|
||||||
|
now := time.Now().Unix()
|
||||||
|
|
||||||
|
assert.Equal(t, claim.UID, uid, "uid should equal")
|
||||||
|
assert.Equal(t, claim.Platform, platform, "platform should equal")
|
||||||
|
assert.Equal(t, claim.RegisteredClaims.ExpiresAt, int64(-1), "StandardClaims.ExpiresAt should be equal")
|
||||||
|
// time difference within 1s
|
||||||
|
assert.Equal(t, claim.RegisteredClaims.IssuedAt, now, "StandardClaims.IssuedAt should be equal")
|
||||||
|
assert.Equal(t, claim.RegisteredClaims.NotBefore, now, "StandardClaims.NotBefore should be equal")
|
||||||
|
|
||||||
|
ttl = int64(60)
|
||||||
|
now = time.Now().Unix()
|
||||||
|
claim = BuildClaims(uid, platform, ttl)
|
||||||
|
// time difference within 1s
|
||||||
|
assert.Equal(t, claim.RegisteredClaims.ExpiresAt, int64(60)+now, "StandardClaims.ExpiresAt should be equal")
|
||||||
|
assert.Equal(t, claim.RegisteredClaims.IssuedAt, now, "StandardClaims.IssuedAt should be equal")
|
||||||
|
assert.Equal(t, claim.RegisteredClaims.NotBefore, now, "StandardClaims.NotBefore should be equal")
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_CreateToken(t *testing.T) {
|
||||||
|
uid := "1"
|
||||||
|
platform := int32(1)
|
||||||
|
now := time.Now().Unix()
|
||||||
|
|
||||||
|
tokenString, expiresAt, err := CreateToken(uid, platform)
|
||||||
|
|
||||||
|
assert.NotEmpty(t, tokenString)
|
||||||
|
assert.Equal(t, expiresAt, 604800+now)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_VerifyToken(t *testing.T) {
|
||||||
|
uid := "1"
|
||||||
|
platform := int32(1)
|
||||||
|
tokenString, _, _ := CreateToken(uid, platform)
|
||||||
|
result := VerifyToken(tokenString, uid)
|
||||||
|
assert.True(t, result)
|
||||||
|
result = VerifyToken(tokenString, "2")
|
||||||
|
assert.False(t, result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_ParseRedisInterfaceToken(t *testing.T) {
|
||||||
|
uid := "1"
|
||||||
|
platform := int32(1)
|
||||||
|
tokenString, _, _ := CreateToken(uid, platform)
|
||||||
|
|
||||||
|
claims, err := ParseRedisInterfaceToken([]uint8(tokenString))
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, claims.UID, uid)
|
||||||
|
|
||||||
|
// timeout
|
||||||
|
config.Config.TokenPolicy.AccessExpire = -80
|
||||||
|
tokenString, _, _ = CreateToken(uid, platform)
|
||||||
|
claims, err = ParseRedisInterfaceToken([]uint8(tokenString))
|
||||||
|
assert.Equal(t, err, TokenExpired)
|
||||||
|
assert.Nil(t, claims)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_ParseToken(t *testing.T) {
|
||||||
|
uid := "1"
|
||||||
|
platform := int32(1)
|
||||||
|
tokenString, _, _ := CreateToken(uid, platform)
|
||||||
|
claims, err := ParseToken(tokenString)
|
||||||
|
if err == nil {
|
||||||
|
assert.Equal(t, claims.UID, uid)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue