GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — host-api/exec/exec_audit_test.go at main · PastureStack/host-api

Expand file tree

/

exec_audit_test.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
59 lines (56 loc) · 2.02 KB
/

exec_audit_test.go

Copy path

File metadata and controls

59 lines (56 loc) · 2.02 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package exec
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"time"
"github.com/PastureStack/host-api/auth"
"github.com/PastureStack/host-api/config"
"github.com/PastureStack/host-api/testutils"
docker "github.com/fsouza/go-dockerclient"
)
func TestExecAuditRequiresActualExitResult(t *testing.T) {
prior := config.Config
defer func() { config.Config = prior }()
var result map[string]string
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
result = make(map[string]string)
json.NewDecoder(r.Body).Decode(&result)
delete(result, "token")
json.NewEncoder(w).Encode(map[string]bool{"accepted": true})
}))
defer server.Close()
config.Config.PlatformURL = server.URL
config.Config.PlatformAccessKey = "agent"
config.Config.PlatformSecretKey = "secret"
config.Config.ParsedPublicKey = testutils.ParseTestPublicKey()
parent := t.TempDir()
if err := os.Chmod(parent, 0700); err != nil {
t.Fatal(err)
}
config.Config.CompletionSpoolDir = filepath.Join(parent, "completion-spool")
for _, candidate := range []struct {
name string
inspect *docker.ExecInspect
err error
outcome, code string
}{
{"zero", &docker.ExecInspect{}, nil, "SUCCEEDED", ""},
{"nonzero", &docker.ExecInspect{ExitCode: 2}, nil, "FAILED", "StreamFailed"},
{"still-running", &docker.ExecInspect{Running: true}, nil, "CANCELLED", "StreamCancelled"},
{"inspect-failed", nil, context.Canceled, "FAILED", "DockerFailure"},
} {
raw := testutils.CreateTokenWithPayload(map[string]interface{}{"apiKeyAudit": map[string]interface{}{"version": 1, "issuedAt": time.Now().Unix(), "fixture": candidate.name}}, testutils.ParseTestPrivateKey())
audit := auth.BeginStreamAudit(raw)
audit.Authorized()
finishExecAudit(audit, candidate.inspect, candidate.err)
audit.Report()
if result["outcome"] != candidate.outcome || result["failureCode"] != candidate.code {
t.Fatalf("%s: wrong terminal result %#v", candidate.name, result)
}
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.