forked from cwtch.im/server
addressing PR concerns + adding servers test
This commit is contained in:
parent
44da3fd95f
commit
8874642601
6
go.mod
6
go.mod
|
@ -3,7 +3,7 @@ module git.openprivacy.ca/cwtch.im/server
|
|||
go 1.14
|
||||
|
||||
require (
|
||||
cwtch.im/cwtch v0.8.5
|
||||
cwtch.im/cwtch v0.12.2
|
||||
git.openprivacy.ca/cwtch.im/tapir v0.4.9
|
||||
git.openprivacy.ca/openprivacy/connectivity v1.5.0
|
||||
git.openprivacy.ca/openprivacy/log v1.0.3
|
||||
|
@ -11,6 +11,4 @@ require (
|
|||
github.com/mattn/go-sqlite3 v1.14.7
|
||||
github.com/struCoder/pidusage v0.2.1
|
||||
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee
|
||||
)
|
||||
|
||||
replace cwtch.im/cwtch => /home/dan/src/go/src/cwtch.im/cwtch
|
||||
)
|
2
go.sum
2
go.sum
|
@ -4,6 +4,8 @@ cwtch.im/cwtch v0.8.0 h1:QDRaDBTXefFRPZPqUMtxoNhOcgXv0rl0bGjysSOmJX0=
|
|||
cwtch.im/cwtch v0.8.0/go.mod h1:+SY/4ueF1U7mK+CX8hZFbtd+GC1lx/cReo110KgtQAw=
|
||||
cwtch.im/cwtch v0.8.5 h1:W67jAF2oRwqWytbZEv1UeCqW0cU2x69tgUw8iy27xFA=
|
||||
cwtch.im/cwtch v0.8.5/go.mod h1:5GHxaaeVnKeXSU64IvtCKzkqhU8DRiLoVM+tiBT8kkc=
|
||||
cwtch.im/cwtch v0.12.2 h1:I+ndKadCRCITw4SPbd+1cpRv+z/7iHjjTUv8OzRwTrE=
|
||||
cwtch.im/cwtch v0.12.2/go.mod h1:QpTkQK7MqNt0dQK9/pBk5VpkvFhy6xuoxJIn401B8fM=
|
||||
filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU=
|
||||
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
|
||||
git.openprivacy.ca/cwtch.im/tapir v0.4.0 h1:clG8uORt0NKEhT4P+Dpw1pzyUuYzYBMevGqn2pciKk8=
|
||||
|
|
|
@ -63,10 +63,6 @@ func NewServer(serverConfig *Config) Server {
|
|||
server := new(server)
|
||||
server.running = false
|
||||
server.config = serverConfig
|
||||
bs := new(persistence.BoltPersistence)
|
||||
bs.Open(path.Join(serverConfig.ConfigDir, "tokens.db"))
|
||||
server.tokenServer = privacypass.NewTokenServerFromStore(&serverConfig.TokenServiceK, bs)
|
||||
log.Infof("Y: %v", server.tokenServer.Y)
|
||||
server.tokenService = server.config.TokenServiceIdentity()
|
||||
server.tokenServicePrivKey = server.config.TokenServerPrivateKey
|
||||
return server
|
||||
|
@ -85,6 +81,11 @@ func (s *server) Run(acn connectivity.ACN) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
bs := new(persistence.BoltPersistence)
|
||||
bs.Open(path.Join(s.config.ConfigDir, "tokens.db"))
|
||||
s.tokenServer = privacypass.NewTokenServerFromStore(&s.config.TokenServiceK, bs)
|
||||
log.Infof("Y: %v", s.tokenServer.Y)
|
||||
|
||||
identity := primitives.InitializeIdentity("", &s.config.PrivateKey, &s.config.PublicKey)
|
||||
var service tapir.Service
|
||||
service = new(tor2.BaseOnionService)
|
||||
|
|
|
@ -132,7 +132,7 @@ func CreateConfig(configDir, filename string, encrypted bool, password string) (
|
|||
if encrypted {
|
||||
key, _, err := v1.InitV1Directory(configDir, password)
|
||||
if err != nil {
|
||||
log.Errorf("Could not create server directory: %s", err)
|
||||
log.Errorf("could not create server directory: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
config.key = key
|
||||
|
@ -183,7 +183,6 @@ func (config *Config) Save() error {
|
|||
defer config.lock.Unlock()
|
||||
bytes, _ := json.MarshalIndent(config, "", "\t")
|
||||
if config.Encrypted {
|
||||
//settingStore := v1.NewFileStore(config.ConfigDir, config.FilePath, config.key)
|
||||
return config.encFileStore.Write(bytes)
|
||||
}
|
||||
return ioutil.WriteFile(path.Join(config.ConfigDir, config.FilePath), bytes, 0600)
|
||||
|
|
|
@ -46,7 +46,6 @@ func NewServers(acn connectivity.ACN, directory string) Servers {
|
|||
func (s *servers) LoadServers(password string) ([]string, error) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
dirs, err := ioutil.ReadDir(s.directory)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error: cannot read server directory: %v", err)
|
||||
|
@ -56,7 +55,7 @@ func (s *servers) LoadServers(password string) ([]string, error) {
|
|||
newConfig, err := LoadConfig(path.Join(s.directory, dir.Name()), ServerConfigFile, true, password)
|
||||
if err == nil {
|
||||
if _, exists := s.servers[newConfig.Onion()]; !exists {
|
||||
log.Debugf("Loaded config, building server for %s\n", newConfig.Onion())
|
||||
log.Debugf("Loaded config, building server for %s\n", newConfig.Onion())
|
||||
server := NewServer(newConfig)
|
||||
s.servers[server.Onion()] = server
|
||||
loadedServers = append(loadedServers, server.Onion())
|
||||
|
@ -111,7 +110,7 @@ func (s *servers) DeleteServer(onion string, password string) error {
|
|||
delete(s.servers, onion)
|
||||
return err
|
||||
}
|
||||
return errors.New("Server not found")
|
||||
return errors.New("server not found")
|
||||
}
|
||||
|
||||
// LaunchServer Run() the specified server
|
||||
|
@ -125,6 +124,8 @@ func (s *servers) LaunchServer(onion string) {
|
|||
|
||||
// ShutdownServer Shutsdown the specified server
|
||||
func (s *servers) ShutdownServer(onion string) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
s.servers[onion].Shutdown()
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"git.openprivacy.ca/openprivacy/connectivity"
|
||||
"git.openprivacy.ca/openprivacy/log"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const TestDir = "./serversTest"
|
||||
const DefaultPassword = "be gay do crime"
|
||||
|
||||
const TestServerDesc = "a test Server"
|
||||
|
||||
func TestServers(t *testing.T) {
|
||||
log.SetLevel(log.LevelDebug)
|
||||
log.Infof("clean up / setup...\n")
|
||||
os.RemoveAll(TestDir)
|
||||
os.Mkdir(TestDir, 0700)
|
||||
|
||||
acn := connectivity.NewLocalACN()
|
||||
log.Infof("NewServers()...\n")
|
||||
servers := NewServers(acn, TestDir)
|
||||
s, err := servers.CreateServer(DefaultPassword)
|
||||
if err != nil {
|
||||
t.Errorf("could not create server: %s", err)
|
||||
return
|
||||
}
|
||||
s.SetAttribute(AttrDescription, TestServerDesc)
|
||||
serverOnion := s.Onion()
|
||||
|
||||
s.Shutdown()
|
||||
|
||||
log.Infof("NewServers()...\n" )
|
||||
servers2 := NewServers(acn, TestDir)
|
||||
log.Infof("LoadServers()...\n")
|
||||
list, err := servers2.LoadServers(DefaultPassword)
|
||||
log.Infof("Loaded!\n")
|
||||
if err != nil {
|
||||
t.Errorf("clould not load server: %s", err)
|
||||
return
|
||||
}
|
||||
if len(list) != 1 {
|
||||
t.Errorf("expected to load 1 server, got %d", len(list))
|
||||
return
|
||||
}
|
||||
|
||||
if list[0] != serverOnion {
|
||||
t.Errorf("expected loaded server to have onion: %s but got %s", serverOnion, list[0])
|
||||
}
|
||||
|
||||
s1 := servers.GetServer(list[0])
|
||||
if s1.GetAttribute(AttrDescription) != TestServerDesc {
|
||||
t.Errorf("expected server description of '%s' but got '%s'", TestServerDesc, s1.GetAttribute(AttrDescription))
|
||||
}
|
||||
|
||||
servers2.Shutdown()
|
||||
os.RemoveAll(TestDir)
|
||||
}
|
|
@ -5,6 +5,7 @@ pwd
|
|||
GORACE="haltonerror=1"
|
||||
go test -race ${1} -coverprofile=server.metrics.cover.out -v ./metrics
|
||||
go test -race ${1} -coverprofile=server.metrics.cover.out -v ./storage
|
||||
go test -race ${1} -coverprofile=server.metrics.cover.out -v ./
|
||||
echo "mode: set" > coverage.out && cat *.cover.out | grep -v mode: | sort -r | \
|
||||
awk '{if($1 != last) {print $0;last=$1}}' >> coverage.out
|
||||
rm -rf *.cover.out
|
||||
|
|
Loading…
Reference in New Issue