Skip to content

Commit

Permalink
skip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantani committed Jul 25, 2024
1 parent 24e2e6d commit af0c035
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 18 deletions.
2 changes: 1 addition & 1 deletion spaceship/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/mholt/archiver/v4 v4.0.0-alpha.8
github.com/pkg/sftp v1.13.6
github.com/stretchr/testify v1.9.0
golang.org/x/crypto v0.24.0
golang.org/x/sync v0.7.0
)

Expand Down Expand Up @@ -269,7 +270,6 @@ require (
go.uber.org/multierr v1.11.0 // indirect
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
golang.org/x/arch v0.6.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
Expand Down
157 changes: 140 additions & 17 deletions spaceship/integration/app_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,150 @@
package integration_test

import (
"bytes"
"fmt"
"net"
"os"
"path/filepath"
"strconv"
"testing"

"github.com/stretchr/testify/require"

pluginsconfig "github.com/ignite/cli/v28/ignite/config/plugins"
"github.com/ignite/cli/v28/ignite/pkg/availableport"
"github.com/ignite/cli/v28/ignite/pkg/cmdrunner/step"
"github.com/ignite/cli/v28/ignite/pkg/errors"
"github.com/ignite/cli/v28/ignite/services/plugin"
envtest "github.com/ignite/cli/v28/integration"
"github.com/stretchr/testify/require"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/terminal"
)

const privateKey = `# random generated pk
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEAzjjvQq3c9tl3W8DHUBlY/lMnr+BhYaRuOn1hTuF9wSNyZY0X35xr
j9E1z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q50CC4whO4QzR6L05nzoaEcGTzcHkrqyuOHwlhyy7QiAXY
856kIsbpf/cF/HM8fqF05LfQM+NENY15IX949a2SWTmANyiq8kMR2+dRsH4hktjLZpCmOz
02dWJOuSTs4/FdWXxEoa7Yj07mInlX3LYE97m83Vg/jPttT/XL9zh+OzlEji3XEQgQM6cp
nSldt0EXsaCKmRAAAADm1vaGFtZWRAZGV2MHgwAQIDBA==
-----END OPENSSH PRIVATE KEY-----`

func newServer(t *testing.T, port uint, user, password string) {
t.Helper()

config := &ssh.ServerConfig{
PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
if c.User() == user && string(pass) == password {
return nil, nil
}
return nil, errors.Errorf("password rejected for %q", c.User())
},
}

private, err := ssh.ParsePrivateKey([]byte(privateKey))
require.NoError(t, err, "failed to parse private key")

config.AddHostKey(private)

// Once a ServerConfig has been configured, connections can be
// accepted.
listener, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port))
require.NoError(t, err, "failed to listen for connection")

go func() {
nConn, err := listener.Accept()
require.NoError(t, err, "failed to accept incoming connection")

// Before use, a handshake must be performed on the incoming
// net.Conn.
_, chans, reqs, err := ssh.NewServerConn(nConn, config)
require.NoError(t, err, "failed to handshake")

// The incoming Request channel must be serviced.
go ssh.DiscardRequests(reqs)

// Service the incoming channel.
for newChannel := range chans {
if newChannel.ChannelType() != "session" {
newChannel.Reject(ssh.UnknownChannelType, "unknown channel type")
continue
}

channel, requests, err := newChannel.Accept()
require.NoError(t, err, "could not accept channel")

go func(in <-chan *ssh.Request) {
for req := range in {
switch req.Type {
case "exec":
// just return error 0 without exec.
channel.SendRequest("exit-status", false, []byte{0, 0, 0, 0})
}
req.Reply(req.Type == "exec", nil)
}
}(requests)

term := terminal.NewTerminal(channel, "> ")
go func() {
defer channel.Close()
for {
line, err := term.ReadLine()
if err != nil {
break
}
fmt.Println(line)
}
}()
}
}()
}

func TestSpaceship(t *testing.T) {
t.Skip("find a better way to deploy a SSH server for tests")

var (
require = require.New(t)
env = envtest.New(t)
app = env.Scaffold("spaceship-app")
require = require.New(t)
env = envtest.New(t)
app = env.Scaffold("spaceship-app")
user = "spaceship"
password = "spaceship_pass"
)

port, err := availableport.Find(1)
require.NoError(err)

newServer(t, port[0], user, password)

dir, err := os.Getwd()
require.NoError(err)
pluginPath := filepath.Join(filepath.Dir(filepath.Dir(dir)), "spaceship")
Expand All @@ -33,27 +157,26 @@ func TestSpaceship(t *testing.T) {
))

// One local plugin expected
assertLocalPlugins(t, app, []pluginsconfig.Plugin{
{
Path: pluginPath,
},
})
assertLocalPlugins(t, app, []pluginsconfig.Plugin{{Path: pluginPath}})
assertGlobalPlugins(t, nil)

buf := &bytes.Buffer{}
env.Must(env.Exec("run spaceship",
step.NewSteps(step.New(
step.Workdir(app.SourcePath()),
step.Stdout(os.Stdout),
step.Stderr(os.Stderr),
step.Stdin(os.Stdin),
step.Exec(
envtest.IgniteApp,
"spaceship",
"hello",
"deploy",
"127.0.0.1",
"-u", user,
"--password", password,
"-p", strconv.Itoa(int(port[0])),
),
step.Workdir(app.SourcePath()),
step.Stdout(buf),
step.Stderr(buf),
)),
))
require.Equal("Hello, world!\n", buf.String())
}

func assertLocalPlugins(t *testing.T, app envtest.App, expectedPlugins []pluginsconfig.Plugin) {
Expand Down

0 comments on commit af0c035

Please sign in to comment.