2021-08-20 15:18:29 +02:00
package server
import (
2022-05-05 08:58:34 +02:00
"net"
"testing"
2022-03-26 12:08:54 +01:00
"github.com/netbirdio/netbird/management/server/jwtclaims"
2022-05-05 08:58:34 +02:00
"github.com/stretchr/testify/assert"
2022-03-01 15:22:18 +01:00
"github.com/stretchr/testify/require"
2021-08-20 15:44:18 +02:00
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
2021-08-20 15:18:29 +02:00
)
2021-12-27 13:17:15 +01:00
func TestAccountManager_GetOrCreateAccountByUser ( t * testing . T ) {
2021-08-20 15:44:18 +02:00
manager , err := createManager ( t )
2021-08-20 15:18:29 +02:00
if err != nil {
t . Fatal ( err )
2021-08-20 15:44:18 +02:00
return
2021-08-20 15:18:29 +02:00
}
2021-12-27 13:17:15 +01:00
userId := "test_user"
2022-02-11 17:18:18 +01:00
account , err := manager . GetOrCreateAccountByUser ( userId , "" )
2021-08-20 15:18:29 +02:00
if err != nil {
t . Fatal ( err )
}
2021-12-27 13:17:15 +01:00
if account == nil {
t . Fatalf ( "expected to create an account for a user %s" , userId )
2021-08-20 15:18:29 +02:00
}
2021-12-27 13:17:15 +01:00
account , err = manager . GetAccountByUser ( userId )
if err != nil {
t . Errorf ( "expected to get existing account after creation, no account was found for a user %s" , userId )
2021-08-20 15:18:29 +02:00
}
2021-12-27 13:17:15 +01:00
if account != nil && account . Users [ userId ] == nil {
2022-03-01 15:22:18 +01:00
t . Fatalf ( "expected to create an account for a user %s but no user was found after creation udner the account %s" , userId , account . Id )
}
}
func TestDefaultAccountManager_GetAccountWithAuthorizationClaims ( t * testing . T ) {
type initUserParams jwtclaims . AuthorizationClaims
type test struct {
2022-03-10 13:47:36 +01:00
name string
inputClaims jwtclaims . AuthorizationClaims
inputInitUserParams initUserParams
inputUpdateAttrs bool
inputUpdateClaimAccount bool
testingFunc require . ComparisonAssertionFunc
expectedMSG string
expectedUserRole UserRole
expectedDomainCategory string
expectedPrimaryDomainStatus bool
2022-03-01 15:22:18 +01:00
}
var (
publicDomain = "public.com"
privateDomain = "private.com"
unknownDomain = "unknown.com"
)
defaultInitAccount := initUserParams {
Domain : publicDomain ,
UserId : "defaultUser" ,
}
testCase1 := test {
name : "New User With Public Domain" ,
inputClaims : jwtclaims . AuthorizationClaims {
Domain : publicDomain ,
UserId : "pub-domain-user" ,
DomainCategory : PublicCategory ,
} ,
2022-03-10 13:47:36 +01:00
inputInitUserParams : defaultInitAccount ,
testingFunc : require . NotEqual ,
expectedMSG : "account IDs shouldn't match" ,
expectedUserRole : UserRoleAdmin ,
expectedDomainCategory : "" ,
expectedPrimaryDomainStatus : false ,
2022-03-01 15:22:18 +01:00
}
initUnknown := defaultInitAccount
initUnknown . DomainCategory = UnknownCategory
initUnknown . Domain = unknownDomain
testCase2 := test {
name : "New User With Unknown Domain" ,
inputClaims : jwtclaims . AuthorizationClaims {
Domain : unknownDomain ,
UserId : "unknown-domain-user" ,
DomainCategory : UnknownCategory ,
} ,
2022-03-10 13:47:36 +01:00
inputInitUserParams : initUnknown ,
testingFunc : require . NotEqual ,
expectedMSG : "account IDs shouldn't match" ,
expectedUserRole : UserRoleAdmin ,
expectedDomainCategory : "" ,
expectedPrimaryDomainStatus : false ,
2022-03-01 15:22:18 +01:00
}
testCase3 := test {
name : "New User With Private Domain" ,
inputClaims : jwtclaims . AuthorizationClaims {
Domain : privateDomain ,
UserId : "pvt-domain-user" ,
DomainCategory : PrivateCategory ,
} ,
2022-03-10 13:47:36 +01:00
inputInitUserParams : defaultInitAccount ,
testingFunc : require . NotEqual ,
expectedMSG : "account IDs shouldn't match" ,
expectedUserRole : UserRoleAdmin ,
expectedDomainCategory : PrivateCategory ,
expectedPrimaryDomainStatus : true ,
2022-03-01 15:22:18 +01:00
}
privateInitAccount := defaultInitAccount
privateInitAccount . Domain = privateDomain
privateInitAccount . DomainCategory = PrivateCategory
testCase4 := test {
name : "New Regular User With Existing Private Domain" ,
inputClaims : jwtclaims . AuthorizationClaims {
Domain : privateDomain ,
UserId : "pvt-domain-user" ,
DomainCategory : PrivateCategory ,
} ,
2022-03-10 13:47:36 +01:00
inputUpdateAttrs : true ,
inputInitUserParams : privateInitAccount ,
testingFunc : require . Equal ,
expectedMSG : "account IDs should match" ,
expectedUserRole : UserRoleUser ,
expectedDomainCategory : PrivateCategory ,
expectedPrimaryDomainStatus : true ,
2022-03-01 15:22:18 +01:00
}
testCase5 := test {
name : "Existing User With Existing Reclassified Private Domain" ,
inputClaims : jwtclaims . AuthorizationClaims {
Domain : defaultInitAccount . Domain ,
UserId : defaultInitAccount . UserId ,
DomainCategory : PrivateCategory ,
} ,
2022-03-10 13:47:36 +01:00
inputInitUserParams : defaultInitAccount ,
testingFunc : require . Equal ,
expectedMSG : "account IDs should match" ,
expectedUserRole : UserRoleAdmin ,
expectedDomainCategory : PrivateCategory ,
expectedPrimaryDomainStatus : true ,
2022-03-01 15:22:18 +01:00
}
2022-03-09 13:31:42 +01:00
testCase6 := test {
name : "Existing Account Id With Existing Reclassified Private Domain" ,
inputClaims : jwtclaims . AuthorizationClaims {
Domain : defaultInitAccount . Domain ,
UserId : defaultInitAccount . UserId ,
DomainCategory : PrivateCategory ,
} ,
2022-03-10 13:47:36 +01:00
inputUpdateClaimAccount : true ,
inputInitUserParams : defaultInitAccount ,
testingFunc : require . Equal ,
expectedMSG : "account IDs should match" ,
expectedUserRole : UserRoleAdmin ,
expectedDomainCategory : PrivateCategory ,
expectedPrimaryDomainStatus : true ,
2022-03-09 13:31:42 +01:00
}
for _ , testCase := range [ ] test { testCase1 , testCase2 , testCase3 , testCase4 , testCase5 , testCase6 } {
2022-03-01 15:22:18 +01:00
t . Run ( testCase . name , func ( t * testing . T ) {
manager , err := createManager ( t )
require . NoError ( t , err , "unable to create account manager" )
initAccount , err := manager . GetAccountByUserOrAccountId ( testCase . inputInitUserParams . UserId , testCase . inputInitUserParams . AccountId , testCase . inputInitUserParams . Domain )
require . NoError ( t , err , "create init user failed" )
if testCase . inputUpdateAttrs {
err = manager . updateAccountDomainAttributes ( initAccount , jwtclaims . AuthorizationClaims { UserId : testCase . inputInitUserParams . UserId , Domain : testCase . inputInitUserParams . Domain , DomainCategory : testCase . inputInitUserParams . DomainCategory } , true )
require . NoError ( t , err , "update init user failed" )
}
2022-03-09 13:31:42 +01:00
if testCase . inputUpdateClaimAccount {
testCase . inputClaims . AccountId = initAccount . Id
}
2022-03-01 15:22:18 +01:00
account , err := manager . GetAccountWithAuthorizationClaims ( testCase . inputClaims )
require . NoError ( t , err , "support function failed" )
testCase . testingFunc ( t , initAccount . Id , account . Id , testCase . expectedMSG )
2022-03-10 13:47:36 +01:00
require . EqualValues ( t , testCase . expectedUserRole , account . Users [ testCase . inputClaims . UserId ] . Role , "expected user role should match" )
require . EqualValues ( t , testCase . expectedDomainCategory , account . DomainCategory , "expected account domain category should match" )
require . EqualValues ( t , testCase . expectedPrimaryDomainStatus , account . IsDomainPrimaryAccount , "expected account primary status should match" )
2022-03-01 15:22:18 +01:00
} )
}
}
2022-05-05 08:58:34 +02:00
2022-03-01 15:22:18 +01:00
func TestAccountManager_PrivateAccount ( t * testing . T ) {
manager , err := createManager ( t )
if err != nil {
t . Fatal ( err )
return
}
userId := "test_user"
account , err := manager . GetOrCreateAccountByUser ( userId , "" )
if err != nil {
t . Fatal ( err )
}
if account == nil {
t . Fatalf ( "expected to create an account for a user %s" , userId )
}
account , err = manager . GetAccountByUser ( userId )
if err != nil {
t . Errorf ( "expected to get existing account after creation, no account was found for a user %s" , userId )
}
if account != nil && account . Users [ userId ] == nil {
2021-12-27 13:17:15 +01:00
t . Fatalf ( "expected to create an account for a user %s but no user was found after creation udner the account %s" , userId , account . Id )
2021-08-20 15:18:29 +02:00
}
2021-08-20 15:44:18 +02:00
}
2022-02-11 17:18:18 +01:00
func TestAccountManager_SetOrUpdateDomain ( t * testing . T ) {
manager , err := createManager ( t )
if err != nil {
t . Fatal ( err )
return
}
userId := "test_user"
domain := "hotmail.com"
account , err := manager . GetOrCreateAccountByUser ( userId , domain )
if err != nil {
t . Fatal ( err )
}
if account == nil {
t . Fatalf ( "expected to create an account for a user %s" , userId )
}
if account . Domain != domain {
t . Errorf ( "setting account domain failed, expected %s, got %s" , domain , account . Domain )
}
domain = "gmail.com"
account , err = manager . GetOrCreateAccountByUser ( userId , domain )
if err != nil {
t . Fatalf ( "got the following error while retrieving existing acc: %v" , err )
}
if account == nil {
t . Fatalf ( "expected to get an account for a user %s" , userId )
}
if account . Domain != domain {
t . Errorf ( "updating domain. expected %s got %s" , domain , account . Domain )
}
}
2021-12-27 13:17:15 +01:00
func TestAccountManager_AddAccount ( t * testing . T ) {
2021-08-20 15:44:18 +02:00
manager , err := createManager ( t )
if err != nil {
t . Fatal ( err )
return
}
expectedId := "test_account"
2021-12-27 13:17:15 +01:00
userId := "account_creator"
expectedPeersSize := 0
expectedSetupKeysSize := 2
expectedNetwork := net . IPNet {
IP : net . IP { 100 , 64 , 0 , 0 } ,
Mask : net . IPMask { 255 , 192 , 0 , 0 } ,
2021-08-20 15:44:18 +02:00
}
2022-02-11 17:18:18 +01:00
account , err := manager . AddAccount ( expectedId , userId , "" )
2021-08-20 15:44:18 +02:00
if err != nil {
t . Fatal ( err )
}
if account . Id != expectedId {
2021-12-27 13:17:15 +01:00
t . Errorf ( "expected account to have Id = %s, got %s" , expectedId , account . Id )
2021-08-20 15:44:18 +02:00
}
2021-12-27 13:17:15 +01:00
if len ( account . Peers ) != expectedPeersSize {
t . Errorf ( "expected account to have len(Peers) = %v, got %v" , expectedPeersSize , len ( account . Peers ) )
2021-08-20 15:44:18 +02:00
}
2021-12-27 13:17:15 +01:00
if len ( account . SetupKeys ) != expectedSetupKeysSize {
t . Errorf ( "expected account to have len(SetupKeys) = %v, got %v" , expectedSetupKeysSize , len ( account . SetupKeys ) )
}
if account . Network . Net . String ( ) != expectedNetwork . String ( ) {
t . Errorf ( "expected account to have Network = %v, got %v" , expectedNetwork . String ( ) , account . Network . Net . String ( ) )
2021-08-20 15:51:29 +02:00
}
2021-08-20 15:44:18 +02:00
}
2022-01-24 11:21:30 +01:00
func TestAccountManager_GetAccountByUserOrAccountId ( t * testing . T ) {
manager , err := createManager ( t )
if err != nil {
t . Fatal ( err )
return
}
userId := "test_user"
2022-02-11 17:18:18 +01:00
account , err := manager . GetAccountByUserOrAccountId ( userId , "" , "" )
2022-01-24 11:21:30 +01:00
if err != nil {
t . Fatal ( err )
}
if account == nil {
t . Fatalf ( "expected to create an account for a user %s" , userId )
}
accountId := account . Id
2022-02-11 17:18:18 +01:00
_ , err = manager . GetAccountByUserOrAccountId ( "" , accountId , "" )
2022-01-24 11:21:30 +01:00
if err != nil {
t . Errorf ( "expected to get existing account after creation using userid, no account was found for a account %s" , accountId )
}
2022-02-11 17:18:18 +01:00
_ , err = manager . GetAccountByUserOrAccountId ( "" , "" , "" )
2022-01-24 11:21:30 +01:00
if err == nil {
t . Errorf ( "expected an error when user and account IDs are empty" )
}
}
2021-08-20 15:44:18 +02:00
func TestAccountManager_AccountExists ( t * testing . T ) {
manager , err := createManager ( t )
if err != nil {
t . Fatal ( err )
return
}
expectedId := "test_account"
2021-12-27 13:17:15 +01:00
userId := "account_creator"
2022-02-11 17:18:18 +01:00
_ , err = manager . AddAccount ( expectedId , userId , "" )
2021-08-20 15:44:18 +02:00
if err != nil {
t . Fatal ( err )
}
exists , err := manager . AccountExists ( expectedId )
if err != nil {
t . Fatal ( err )
}
if ! * exists {
t . Errorf ( "expected account to exist after creation, got false" )
}
}
func TestAccountManager_GetAccount ( t * testing . T ) {
manager , err := createManager ( t )
if err != nil {
t . Fatal ( err )
return
}
expectedId := "test_account"
2021-12-27 13:17:15 +01:00
userId := "account_creator"
2022-02-11 17:18:18 +01:00
account , err := manager . AddAccount ( expectedId , userId , "" )
2021-08-20 15:44:18 +02:00
if err != nil {
t . Fatal ( err )
}
2022-05-21 15:21:39 +02:00
// AddAccount has been already tested so we can assume it is correct and compare results
2022-02-11 17:18:18 +01:00
getAccount , err := manager . GetAccountById ( expectedId )
2021-08-20 15:44:18 +02:00
if err != nil {
t . Fatal ( err )
return
}
if account . Id != getAccount . Id {
2021-08-20 22:33:43 +02:00
t . Errorf ( "expected account.Id %s, got %s" , account . Id , getAccount . Id )
2021-08-20 15:44:18 +02:00
}
for _ , peer := range account . Peers {
if _ , ok := getAccount . Peers [ peer . Key ] ; ! ok {
t . Errorf ( "expected account to have peer %s, not found" , peer . Key )
}
}
for _ , key := range account . SetupKeys {
if _ , ok := getAccount . SetupKeys [ key . Key ] ; ! ok {
t . Errorf ( "expected account to have setup key %s, not found" , key . Key )
}
}
2021-08-20 15:18:29 +02:00
}
func TestAccountManager_AddPeer ( t * testing . T ) {
2021-08-20 15:44:18 +02:00
manager , err := createManager ( t )
if err != nil {
t . Fatal ( err )
return
}
2021-08-20 15:18:29 +02:00
2022-02-11 17:18:18 +01:00
account , err := manager . AddAccount ( "test_account" , "account_creator" , "" )
2021-08-20 15:18:29 +02:00
if err != nil {
t . Fatal ( err )
}
2022-05-21 15:21:39 +02:00
serial := account . Network . CurrentSerial ( ) // should be 0
2022-01-14 14:34:27 +01:00
2021-08-20 15:44:18 +02:00
var setupKey * SetupKey
for _ , key := range account . SetupKeys {
setupKey = key
}
if setupKey == nil {
t . Errorf ( "expecting account to have a default setup key" )
return
}
2021-08-20 15:18:29 +02:00
2022-03-10 18:18:38 +01:00
if account . Network . Serial != 0 {
t . Errorf ( "expecting account network to have an initial Serial=0" )
2022-01-14 14:34:27 +01:00
return
}
2022-01-16 17:10:36 +01:00
key , err := wgtypes . GeneratePrivateKey ( )
2021-08-20 15:18:29 +02:00
if err != nil {
t . Fatal ( err )
2021-08-20 15:44:18 +02:00
return
}
expectedPeerKey := key . PublicKey ( ) . String ( )
expectedPeerIP := "100.64.0.1"
2022-05-05 20:02:15 +02:00
expectedSetupKey := setupKey . Key
2021-08-20 15:44:18 +02:00
2022-05-05 20:02:15 +02:00
peer , err := manager . AddPeer ( setupKey . Key , "" , & Peer {
2021-08-24 11:50:19 +02:00
Key : expectedPeerKey ,
Meta : PeerSystemMeta { } ,
Name : expectedPeerKey ,
} )
2021-08-20 15:44:18 +02:00
if err != nil {
t . Errorf ( "expecting peer to be added, got failure %v" , err )
return
}
2022-02-11 17:18:18 +01:00
account , err = manager . GetAccountById ( account . Id )
2022-01-14 14:34:27 +01:00
if err != nil {
t . Fatal ( err )
return
}
2021-08-20 15:44:18 +02:00
if peer . Key != expectedPeerKey {
t . Errorf ( "expecting just added peer to have key = %s, got %s" , expectedPeerKey , peer . Key )
}
2022-05-05 20:02:15 +02:00
if peer . IP . String ( ) != expectedPeerIP {
t . Errorf ( "expecting just added peer to have IP = %s, got %s" , expectedPeerIP , peer . IP . String ( ) )
}
if peer . SetupKey != expectedSetupKey {
t . Errorf ( "expecting just added peer to have SetupKey = %s, got %s" , expectedSetupKey , peer . SetupKey )
}
if account . Network . CurrentSerial ( ) != 1 {
t . Errorf ( "expecting Network Serial=%d to be incremented by 1 and be equal to %d when adding new peer to account" , serial , account . Network . CurrentSerial ( ) )
}
}
func TestAccountManager_AddPeerWithUserID ( t * testing . T ) {
manager , err := createManager ( t )
if err != nil {
t . Fatal ( err )
return
}
userId := "account_creator"
account , err := manager . GetOrCreateAccountByUser ( userId , "" )
if err != nil {
t . Fatal ( err )
}
2022-05-21 15:21:39 +02:00
serial := account . Network . CurrentSerial ( ) // should be 0
2022-05-05 20:02:15 +02:00
if account . Network . Serial != 0 {
t . Errorf ( "expecting account network to have an initial Serial=0" )
return
}
key , err := wgtypes . GeneratePrivateKey ( )
if err != nil {
t . Fatal ( err )
return
}
expectedPeerKey := key . PublicKey ( ) . String ( )
expectedPeerIP := "100.64.0.1"
expectedUserId := userId
peer , err := manager . AddPeer ( "" , userId , & Peer {
Key : expectedPeerKey ,
Meta : PeerSystemMeta { } ,
Name : expectedPeerKey ,
} )
if err != nil {
t . Errorf ( "expecting peer to be added, got failure %v, account users: %v" , err , account . CreatedBy )
return
}
account , err = manager . GetAccountById ( account . Id )
if err != nil {
t . Fatal ( err )
return
}
2021-08-20 15:44:18 +02:00
if peer . Key != expectedPeerKey {
2022-05-05 20:02:15 +02:00
t . Errorf ( "expecting just added peer to have key = %s, got %s" , expectedPeerKey , peer . Key )
}
if peer . IP . String ( ) != expectedPeerIP {
2021-08-20 15:44:18 +02:00
t . Errorf ( "expecting just added peer to have IP = %s, got %s" , expectedPeerIP , peer . IP . String ( ) )
2021-08-20 15:18:29 +02:00
}
2022-05-05 20:02:15 +02:00
if peer . UserID != expectedUserId {
t . Errorf ( "expecting just added peer to have UserID = %s, got %s" , expectedUserId , peer . UserID )
}
2022-03-10 18:18:38 +01:00
if account . Network . CurrentSerial ( ) != 1 {
t . Errorf ( "expecting Network Serial=%d to be incremented by 1 and be equal to %d when adding new peer to account" , serial , account . Network . CurrentSerial ( ) )
2022-01-14 14:34:27 +01:00
}
2021-08-20 15:44:18 +02:00
}
2022-01-14 14:34:27 +01:00
func TestAccountManager_DeletePeer ( t * testing . T ) {
manager , err := createManager ( t )
if err != nil {
t . Fatal ( err )
return
}
2022-02-11 17:18:18 +01:00
account , err := manager . AddAccount ( "test_account" , "account_creator" , "" )
2022-01-14 14:34:27 +01:00
if err != nil {
t . Fatal ( err )
}
var setupKey * SetupKey
for _ , key := range account . SetupKeys {
setupKey = key
}
key , err := wgtypes . GenerateKey ( )
if err != nil {
t . Fatal ( err )
return
}
peerKey := key . PublicKey ( ) . String ( )
2022-05-05 20:02:15 +02:00
_ , err = manager . AddPeer ( setupKey . Key , "" , & Peer {
2022-01-14 14:34:27 +01:00
Key : peerKey ,
Meta : PeerSystemMeta { } ,
Name : peerKey ,
} )
if err != nil {
t . Errorf ( "expecting peer to be added, got failure %v" , err )
return
}
_ , err = manager . DeletePeer ( account . Id , peerKey )
if err != nil {
return
}
2022-02-11 17:18:18 +01:00
account , err = manager . GetAccountById ( account . Id )
2022-01-14 14:34:27 +01:00
if err != nil {
t . Fatal ( err )
return
}
2022-03-10 18:18:38 +01:00
if account . Network . CurrentSerial ( ) != 2 {
t . Errorf ( "expecting Network Serial=%d to be incremented and be equal to 2 after adding and deleteing a peer" , account . Network . CurrentSerial ( ) )
2022-01-14 14:34:27 +01:00
}
}
2022-05-05 08:58:34 +02:00
func TestGetUsersFromAccount ( t * testing . T ) {
manager , err := createManager ( t )
if err != nil {
t . Fatal ( err )
}
users := map [ string ] * User { "1" : { Id : "1" , Role : "admin" } , "2" : { Id : "2" , Role : "user" } , "3" : { Id : "3" , Role : "user" } }
accountId := "test_account_id"
account , err := manager . AddAccount ( accountId , users [ "1" ] . Id , "" )
if err != nil {
t . Fatal ( err )
}
// add a user to the account
for _ , user := range users {
account . Users [ user . Id ] = user
}
userInfos , err := manager . GetUsersFromAccount ( accountId )
if err != nil {
t . Fatal ( err )
}
for _ , userInfo := range userInfos {
id := userInfo . ID
assert . Equal ( t , userInfo . ID , users [ id ] . Id )
assert . Equal ( t , string ( userInfo . Role ) , string ( users [ id ] . Role ) )
assert . Equal ( t , userInfo . Name , "" )
assert . Equal ( t , userInfo . Email , "" )
}
}
2022-05-23 13:03:57 +02:00
func TestAccountManager_UpdatePeerMeta ( t * testing . T ) {
manager , err := createManager ( t )
if err != nil {
t . Fatal ( err )
return
}
account , err := manager . AddAccount ( "test_account" , "account_creator" , "" )
if err != nil {
t . Fatal ( err )
}
var setupKey * SetupKey
for _ , key := range account . SetupKeys {
setupKey = key
}
key , err := wgtypes . GeneratePrivateKey ( )
if err != nil {
t . Fatal ( err )
return
}
peer , err := manager . AddPeer ( setupKey . Key , "" , & Peer {
Key : key . PublicKey ( ) . String ( ) ,
Meta : PeerSystemMeta {
Hostname : "Hostname" ,
GoOS : "GoOS" ,
Kernel : "Kernel" ,
Core : "Core" ,
Platform : "Platform" ,
OS : "OS" ,
WtVersion : "WtVersion" ,
} ,
Name : key . PublicKey ( ) . String ( ) ,
} )
if err != nil {
t . Errorf ( "expecting peer to be added, got failure %v" , err )
return
}
newMeta := PeerSystemMeta {
Hostname : "new-Hostname" ,
GoOS : "new-GoOS" ,
Kernel : "new-Kernel" ,
Core : "new-Core" ,
Platform : "new-Platform" ,
OS : "new-OS" ,
WtVersion : "new-WtVersion" ,
}
err = manager . UpdatePeerMeta ( peer . Key , newMeta )
if err != nil {
t . Error ( err )
return
}
p , err := manager . GetPeer ( peer . Key )
if err != nil {
return
}
if err != nil {
t . Fatal ( err )
return
}
assert . Equal ( t , newMeta , p . Meta )
}
2022-02-22 11:28:19 +01:00
func createManager ( t * testing . T ) ( * DefaultAccountManager , error ) {
2021-08-20 15:44:18 +02:00
store , err := createStore ( t )
if err != nil {
return nil , err
}
2022-05-21 15:21:39 +02:00
return BuildManager ( store , NewPeersUpdateManager ( ) , nil )
2021-08-20 15:18:29 +02:00
}
func createStore ( t * testing . T ) ( Store , error ) {
dataDir := t . TempDir ( )
store , err := NewStore ( dataDir )
if err != nil {
return nil , err
}
return store , nil
}