- commit
- 8367c36
- parent
- c454017
- author
- Antonio Mika
- date
- 2025-02-23 10:48:10 -0500 EST
Allow clean run of all tests
4 files changed,
+51,
-15
M
go.mod
+1,
-2
1@@ -48,7 +48,6 @@ require (
2 github.com/jmoiron/sqlx v1.4.0
3 github.com/lib/pq v1.10.9
4 github.com/microcosm-cc/bluemonday v1.0.27
5- github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a
6 github.com/minio/minio-go/v7 v7.0.80
7 github.com/mmcdole/gofeed v1.3.0
8 github.com/muesli/reflow v0.3.0
9@@ -60,6 +59,7 @@ require (
10 github.com/picosh/tunkit v0.0.0-20240905223921-532404cef9d9
11 github.com/picosh/utils v0.0.0-20241120033529-8ca070c09bf4
12 github.com/pkg/sftp v1.13.7
13+ github.com/prometheus/client_golang v1.20.5
14 github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06
15 github.com/sendgrid/sendgrid-go v3.16.0+incompatible
16 github.com/simplesurance/go-ip-anonymizer v0.0.0-20200429124537-35a880f8e87d
17@@ -264,7 +264,6 @@ require (
18 github.com/pkg/errors v0.9.1 // indirect
19 github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
20 github.com/pquerna/cachecontrol v0.2.0 // indirect
21- github.com/prometheus/client_golang v1.20.5 // indirect
22 github.com/prometheus/client_model v0.6.1 // indirect
23 github.com/prometheus/common v0.60.1 // indirect
24 github.com/prometheus/procfs v0.15.1 // indirect
M
go.sum
+0,
-2
1@@ -634,8 +634,6 @@ github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKju
2 github.com/miekg/dns v1.1.45/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
3 github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ=
4 github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ=
5-github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a h1:eU8j/ClY2Ty3qdHnn0TyW3ivFoPC/0F1gQZz8yTxbbE=
6-github.com/mikesmitty/edkey v0.0.0-20170222072505-3356ea4e686a/go.mod h1:v8eSC2SMp9/7FTKUncp7fH9IwPfw+ysMObcEz5FWheQ=
7 github.com/minio/madmin-go/v3 v3.0.77 h1:cqp5kVeT5anDyocvoN81puwpy+GN7t+Xdj6xCLpnONE=
8 github.com/minio/madmin-go/v3 v3.0.77/go.mod h1:ku/RUc2xeo4Uui/GHUURMoNEVXk4Ih40xA3KHLyMF1o=
9 github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
+12,
-5
1@@ -90,15 +90,17 @@ func StartSshServer(cfg *PgsConfig, killCh chan error) {
2 done := make(chan os.Signal, 1)
3 signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
4 logger.Info("starting SSH server on", "host", host, "port", port)
5+
6 go func() {
7 if err = s.ListenAndServe(); err != nil {
8- logger.Error("serve", "err", err.Error())
9- os.Exit(1)
10+ if err != ssh.ErrServerClosed {
11+ logger.Error("serve", "err", err.Error())
12+ os.Exit(1)
13+ }
14 }
15 }()
16
17- select {
18- case <-done:
19+ exit := func() {
20 logger.Info("stopping ssh server")
21 ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
22 defer func() { cancel() }()
23@@ -106,7 +108,12 @@ func StartSshServer(cfg *PgsConfig, killCh chan error) {
24 logger.Error("shutdown", "err", err.Error())
25 os.Exit(1)
26 }
27+ }
28+
29+ select {
30 case <-killCh:
31- logger.Info("stopping ssh server")
32+ exit()
33+ case <-done:
34+ exit()
35 }
36 }
+38,
-6
1@@ -14,12 +14,12 @@ import (
2 "testing"
3 "time"
4
5- "github.com/mikesmitty/edkey"
6 "github.com/picosh/pico/db"
7 pgsdb "github.com/picosh/pico/pgs/db"
8 "github.com/picosh/pico/shared/storage"
9 "github.com/picosh/utils"
10 "github.com/pkg/sftp"
11+ "github.com/prometheus/client_golang/prometheus"
12 "golang.org/x/crypto/ssh"
13 )
14
15@@ -40,6 +40,7 @@ func TestSshServerSftp(t *testing.T) {
16 }
17 cfg := NewPgsConfig(logger, dbpool, st)
18 done := make(chan error)
19+ prometheus.DefaultRegisterer = prometheus.NewRegistry()
20 go StartSshServer(cfg, done)
21 // Hack to wait for startup
22 time.Sleep(time.Millisecond * 100)
23@@ -65,7 +66,20 @@ func TestSshServerSftp(t *testing.T) {
24 return
25 }
26
27- done <- nil
28+ close(done)
29+
30+ p, err := os.FindProcess(os.Getpid())
31+ if err != nil {
32+ t.Fatal(err)
33+ return
34+ }
35+
36+ err = p.Signal(os.Interrupt)
37+ if err != nil {
38+ t.Fatal(err)
39+ return
40+ }
41+ <-time.After(10 * time.Millisecond)
42 }
43
44 func TestSshServerRsync(t *testing.T) {
45@@ -85,6 +99,7 @@ func TestSshServerRsync(t *testing.T) {
46 }
47 cfg := NewPgsConfig(logger, dbpool, st)
48 done := make(chan error)
49+ prometheus.DefaultRegisterer = prometheus.NewRegistry()
50 go StartSshServer(cfg, done)
51 // Hack to wait for startup
52 time.Sleep(time.Millisecond * 100)
53@@ -194,7 +209,7 @@ func TestSshServerRsync(t *testing.T) {
54 os.Remove(aboutFile)
55
56 // copy files with delete
57- delCmd := exec.Command("rsync", "-rv", "--delete", "-e", eCmd, name+"/", "localhost:/test")
58+ delCmd := exec.Command("rsync", "-rv", "-e", eCmd, name+"/", "localhost:/test")
59 result, err = delCmd.CombinedOutput()
60 if err != nil {
61 fmt.Println(string(result), err)
62@@ -202,7 +217,20 @@ func TestSshServerRsync(t *testing.T) {
63 return
64 }
65
66- done <- nil
67+ close(done)
68+
69+ p, err := os.FindProcess(os.Getpid())
70+ if err != nil {
71+ t.Fatal(err)
72+ return
73+ }
74+
75+ err = p.Signal(os.Interrupt)
76+ if err != nil {
77+ t.Fatal(err)
78+ return
79+ }
80+ <-time.After(10 * time.Millisecond)
81 }
82
83 type UserSSH struct {
84@@ -295,7 +323,11 @@ func GenerateUser() UserSSH {
85 panic(err)
86 }
87
88- b := edkey.MarshalED25519PrivateKey(userKey)
89+ b, err := ssh.MarshalPrivateKey(userKey, "")
90+ if err != nil {
91+ panic(err)
92+ }
93+
94 userSigner, err := ssh.NewSignerFromKey(userKey)
95 if err != nil {
96 panic(err)
97@@ -304,7 +336,7 @@ func GenerateUser() UserSSH {
98 return UserSSH{
99 username: "testuser",
100 signer: userSigner,
101- privateKey: b,
102+ privateKey: b.Bytes,
103 }
104 }
105