Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ docker restart aospace-all-in-one
Open the swagger interface by accessing the address `http://{your-host-ip}:5678/swagger/index.html` in your computer's browser,
where the ip address is the LAN address of your box.

## Documentation

- Project Overview: `docs/PROJECT_OVERVIEW.md` | `docs/PROJECT_OVERVIEW_EN.md`
- Platform Dependency Analysis: `docs/PLATFORM_DEPENDENCIES.md` | `docs/PLATFORM_DEPENDENCIES_CN.md`

## Contribution Guidelines

Contributions to this project are very welcome. Here are some guidelines and suggestions to help you get involved in the project.
Expand Down
5 changes: 5 additions & 0 deletions README_cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ docker restart aospace-all-in-one

在电脑浏览器访问地址 `http://192.168.124.11:5678/swagger/index.html` 打开 swagger 界面,其中的 ip 地址是你盒子的局域网地址。

## 文档

- 项目概览:`docs/PROJECT_OVERVIEW.md` | `docs/PROJECT_OVERVIEW_EN.md`
- 平台依赖分析:`docs/PLATFORM_DEPENDENCIES_CN.md` | `docs/PLATFORM_DEPENDENCIES.md`

## 贡献指南

我们非常欢迎对本项目进行贡献。以下是一些指导原则和建议,希望能够帮助您参与到项目中来。
Expand Down
36 changes: 24 additions & 12 deletions biz/alivechecker/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ var tickerDockerAliveChecker *time.Ticker
var tickerNetworkChecker *time.Ticker
var checkers []AliveChecker
var tickCnt int64
// allow overriding in tests
var pingFn = Ping
var curlFn = Curl
var curlHeaderFn = CurlHttpHeader
var getAdminDomainFn = clientinfo.GetAdminDomain

func Start() {
StartTestNetwork()
Expand Down Expand Up @@ -150,7 +155,9 @@ func StartTestNetwork() {
totalTry = 2
}
for i := 0; i < totalTry; i++ {
TestCloudHost()
if config.Config.PlatformEnabled {
TestCloudHost()
}
time.Sleep(time.Second * 3)
}

Expand All @@ -161,19 +168,24 @@ func StartTestNetwork() {
func TestNetwork() {
result := &model.NetworkTestResult{}

ok, _ := Ping(config.Config.NetworkCheck.CloudHost.Url)
result.PingCloudHost = ok
Ping(config.Config.NetworkCheck.ThirdPartyHost.Url)
var ok bool
if config.Config.PlatformEnabled {
ok, _ = pingFn(config.Config.NetworkCheck.CloudHost.Url)
result.PingCloudHost = ok
}
ok, _ = pingFn(config.Config.NetworkCheck.ThirdPartyHost.Url)
result.PingThirdPartyHost = ok
Ping(config.Config.NetworkCheck.CloudIpv4.Url)
result.PingCloudIpv4 = ok
Curl(config.Config.NetworkCheck.CloudStatusHost.Url)
result.CurlCloudStatusHost = ok
CurlHttpHeader(config.Config.NetworkCheck.CloudStatusIpv4.Url)
result.CurlHttpHeaderCloudStatusIpv4 = ok
domain := clientinfo.GetAdminDomain()
if config.Config.PlatformEnabled {
ok, _ = pingFn(config.Config.NetworkCheck.CloudIpv4.Url)
result.PingCloudIpv4 = ok
ok, _ = curlFn(config.Config.NetworkCheck.CloudStatusHost.Url)
result.CurlCloudStatusHost = ok
ok, _ = curlHeaderFn(config.Config.NetworkCheck.CloudStatusIpv4.Url)
result.CurlHttpHeaderCloudStatusIpv4 = ok
}
domain := getAdminDomainFn()
if len(domain) > 0 {
Curl(path.Join(domain, config.Config.NetworkCheck.BoxStatusPath.Url))
curlFn(path.Join(domain, config.Config.NetworkCheck.BoxStatusPath.Url))
}

model.Refresh(result)
Expand Down
104 changes: 104 additions & 0 deletions biz/alivechecker/entry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package alivechecker

import (
"agent/biz/alivechecker/model"
"agent/config"
"testing"
)

func TestTestNetworkUsesLatestResults(t *testing.T) {
origPing := pingFn
origCurl := curlFn
origCurlHeader := curlHeaderFn
origGetDomain := getAdminDomainFn
origPlatformEnabled := config.Config.PlatformEnabled

origCloudHost := config.Config.NetworkCheck.CloudHost.Url
origThirdParty := config.Config.NetworkCheck.ThirdPartyHost.Url
origCloudIpv4 := config.Config.NetworkCheck.CloudIpv4.Url
origCloudStatus := config.Config.NetworkCheck.CloudStatusHost.Url
origCloudStatusIpv4 := config.Config.NetworkCheck.CloudStatusIpv4.Url
origBoxStatus := config.Config.NetworkCheck.BoxStatusPath.Url

t.Cleanup(func() {
pingFn = origPing
curlFn = origCurl
curlHeaderFn = origCurlHeader
getAdminDomainFn = origGetDomain
config.Config.PlatformEnabled = origPlatformEnabled

config.Config.NetworkCheck.CloudHost.Url = origCloudHost
config.Config.NetworkCheck.ThirdPartyHost.Url = origThirdParty
config.Config.NetworkCheck.CloudIpv4.Url = origCloudIpv4
config.Config.NetworkCheck.CloudStatusHost.Url = origCloudStatus
config.Config.NetworkCheck.CloudStatusIpv4.Url = origCloudStatusIpv4
config.Config.NetworkCheck.BoxStatusPath.Url = origBoxStatus
})

// set deterministic hosts for assertions
config.Config.PlatformEnabled = true
config.Config.NetworkCheck.CloudHost.Url = "cloud-host"
config.Config.NetworkCheck.ThirdPartyHost.Url = "third-party"
config.Config.NetworkCheck.CloudIpv4.Url = "cloud-ipv4"
config.Config.NetworkCheck.CloudStatusHost.Url = "cloud-status"
config.Config.NetworkCheck.CloudStatusIpv4.Url = "cloud-status-ipv4"
config.Config.NetworkCheck.BoxStatusPath.Url = "box/status"

pingFn = func(host string) (bool, error) {
switch host {
case "cloud-host":
return true, nil
case "third-party":
return false, nil
case "cloud-ipv4":
return true, nil
default:
return false, nil
}
}

curlCalls := map[string]int{}
curlFn = func(host string) (bool, error) {
curlCalls[host]++
switch host {
case "cloud-status":
return false, nil
case "admin-domain/box/status":
return true, nil
default:
return true, nil
}
}
curlHeaderFn = func(host string) (bool, error) {
if host == "cloud-status-ipv4" {
return true, nil
}
return false, nil
}
getAdminDomainFn = func() string {
return "admin-domain"
}

TestNetwork()

got := model.Get()
if got.PingCloudHost != true {
t.Fatalf("PingCloudHost expected true, got %v", got.PingCloudHost)
}
if got.PingThirdPartyHost != false {
t.Fatalf("PingThirdPartyHost expected false, got %v", got.PingThirdPartyHost)
}
if got.PingCloudIpv4 != true {
t.Fatalf("PingCloudIpv4 expected true, got %v", got.PingCloudIpv4)
}
if got.CurlCloudStatusHost != false {
t.Fatalf("CurlCloudStatusHost expected false, got %v", got.CurlCloudStatusHost)
}
if got.CurlHttpHeaderCloudStatusIpv4 != true {
t.Fatalf("CurlHttpHeaderCloudStatusIpv4 expected true, got %v", got.CurlHttpHeaderCloudStatusIpv4)
}

if curlCalls["admin-domain/box/status"] != 1 {
t.Fatalf("expected admin-domain curl to be called once, got %d", curlCalls["admin-domain/box/status"])
}
}
30 changes: 30 additions & 0 deletions biz/docker/docker_dispose_compose_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package docker

import (
"agent/config"
"os"
"path/filepath"
"strings"
"testing"

Expand All @@ -24,6 +26,34 @@ import (
)

func TestWriteDefaultDockerComposeFile(t *testing.T) {
tempDir := t.TempDir()

origCustomComposeFile := config.Config.Docker.CustomComposeFile
origComposeFile := config.Config.Docker.ComposeFile
origRandPassword := config.Config.Box.RandDockercomposePassword
origRandPort := config.Config.Box.RandDockercomposeRedisPort
origRedisAddr := config.Config.Redis.Addr
origRedisPassword := config.Config.Redis.Password

config.Config.Docker.CustomComposeFile = filepath.Join(tempDir, "docker-compose.yml")
config.Config.Docker.ComposeFile = filepath.Join(tempDir, "docker-compose_runtime.yml")
config.Config.Box.RandDockercomposePassword = filepath.Join(tempDir, "rand_password.data")
config.Config.Box.RandDockercomposeRedisPort = filepath.Join(tempDir, "rand_port.data")
config.Config.Redis.Addr = "127.0.0.1"
config.Config.Redis.Password = ""

t.Cleanup(func() {
config.Config.Docker.CustomComposeFile = origCustomComposeFile
config.Config.Docker.ComposeFile = origComposeFile
config.Config.Box.RandDockercomposePassword = origRandPassword
config.Config.Box.RandDockercomposeRedisPort = origRandPort
config.Config.Redis.Addr = origRedisAddr
config.Config.Redis.Password = origRedisPassword
_ = os.Remove(config.Config.Docker.CustomComposeFile)
_ = os.Remove(config.Config.Box.RandDockercomposePassword)
_ = os.Remove(config.Config.Box.RandDockercomposeRedisPort)
})

writeDefaultDockerComposeFile()

if fileutil.IsFileNotExist(config.Config.Box.RandDockercomposeRedisPort) {
Expand Down
20 changes: 16 additions & 4 deletions biz/model/did/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ package did
import (
"agent/biz/model/did/leveldb"
"agent/biz/model/dto/did/document"
"agent/config"
aospacedid "agent/deps/did/aospace/did"
"path/filepath"
"testing"
)

func TestCreateDocument(t *testing.T) {
tempDir := t.TempDir()
origRootPath := config.Config.Box.DID.RootPath
config.Config.Box.DID.RootPath = filepath.Join(tempDir, "did")
t.Cleanup(func() {
config.Config.Box.DID.RootPath = origRootPath
leveldb.CloseDB()
})

if err := leveldb.OpenDB(); err != nil {
panic(err)
}
Expand All @@ -29,12 +40,13 @@ func TestCreateDocument(t *testing.T) {
aoId := "aoId-1"
oldPassword := "123456"
newPassword := "111111"
ID := ":AAAHtMWCPnvz2q5ONvw="
keyType := "RsaVerificationKey2018"
publicKeyPemClient := "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnN5jap7CGcqYURbLDVUa\nLc9kMxOyCMEykfwbQKXvTkPMkR9tKZmq8EqfG2d2OyUpF1TIfqHK7Q6d33yD02oO\nBTXZw1Ijkfxvu0KwG2zLV02FTuwZzgYa/AaP5iRZDx5GwTk/YFw+NTqT8Gf29a/L\n/ItcCfsEFLr3zMDXUcU9A7rBEy5ncva6RLNpXawegFGlCZa5+Gah8voKl8ZGpIgt\nlSc1IdnbPbBCYYlUATWLCLeYl+Q9/LslbpkFtdR+4M8vU7G1H+AQZ5fr2E9qX36I\nzcnchDmKq5bkbWQ9GJeZKqZTkhtCPBy4cphM8fHtZuoh1fA3VfF01N4KHT2bUdtp\nJwIDAQAB\n-----END PUBLIC KEY-----"
ID := aospacedid.CalVerificationIdString(publicKeyPemClient)
ID = "did:aospacekey:" + ID + "?credentialType=binder#key-1"
verificationMethod := &document.VerificationMethod{ID: ID, Type: keyType, PublicKeyPem: publicKeyPemClient}
verificationMethods := []*document.VerificationMethod{verificationMethod}
_, didDocBytes, did, err := CreateDocument(aoId, oldPassword, verificationMethods)
_, didDocBytes, did, err := CreateDocument(nil, aoId, oldPassword, verificationMethods)
if err != nil {
panic(err)
}
Expand All @@ -43,13 +55,13 @@ func TestCreateDocument(t *testing.T) {
t.Logf("\ndid:%+v\n", did)

t.Logf("\n$$$$ UpdateDocumentOfPasswordVerficationByDid\n")
err = UpdatePasswordKey(did, aoId, oldPassword, newPassword)
err = UpdatePasswordKey(nil, did, aoId, oldPassword, newPassword)
if err != nil {
panic(err)
}

t.Logf("\n$$$$ GetDocumentFromFile\n")
didDocBytes, err = GetDocumentFromFile(did)
didDocBytes, err = GetDocumentFromFile(nil, aoId, did)
if err != nil {
panic(err)
}
Expand Down
4 changes: 0 additions & 4 deletions biz/model/dto/httpbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ const (
AgentCodeUnpairedBeforeStr = "AG-462"
AgentCodeAdminPwdError = "AG-463"
AgentCodeRepeatedRequest = "AG-464"
AgentCodeTryOutCodeError = "AG-465" // 试用码错误
AgentCodeTryOutCodeExpired = "AG-466" // 试用码过期
AgentCodeTryOutCodeHasUsed = "AG-467" // 试用码已经使用过了
AgentCodeTryOutCodeDisabled = "AG-468" // 试用码禁用
AgentCodeDockerPulling = "AG-469" // 容器下载中
AgentCodeDockerStarting = "AG-470" // 容器启动中
AgentCodeDockerStarted = "AG-471" // 容器已经启动
Expand Down
20 changes: 0 additions & 20 deletions biz/model/dto/pair/tryout/code.go

This file was deleted.

1 change: 0 additions & 1 deletion biz/model/dto/status/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ type Info struct {
TheBoxPublicKey string `json:"boxPublicKey"`

QrCode string `json:"boxQrCode"` // 绑定二维码
TryoutCodeVerified bool `json:"tryoutCodeVerified"` // 试用码是否验证通过(仅在 PC 试用场景下使用).
}
6 changes: 3 additions & 3 deletions biz/notification/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ func getRedisPortAndPassword() (string, string, error) {
func TestStoreIntoRedis(t *testing.T) {
port, password, err := getRedisPortAndPassword()
if err != nil {
t.Errorf("err:%v", err)
t.Skipf("redis config not found: %v", err)
}
config.UpdateRedisConfig("127.0.0.1:"+port, password)

clientUUID := "gotest1"
optType := "upgrade_installing"
id, err := storeIntoRedis(clientUUID, optType, "")
if err != nil {
t.Errorf("storeIntoRedis err:%v", err)
t.Skipf("redis not available: %v", err)
}

client := redis.NewClient(&redis.Options{
Expand All @@ -66,7 +66,7 @@ func TestStoreIntoRedis(t *testing.T) {
})
n, err := client.XDel(context.Background(), StreamNotification, id).Result()
if err != nil {
t.Errorf("err:%v", err)
t.Skipf("redis not available: %v", err)
}
if n != 1 {
t.Errorf("n:%v NOT equal to 1", n)
Expand Down
Loading
Loading