GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — host-api/exec/exec_audit_test.go at main · PastureStack/host-api Expand file tree/ Copy pathexec_audit_test.goMore file actions 59 lines (56 loc) · 2.02 KB / Copy pathexec_audit_test.goFile metadata and controls59 lines (56 loc) · 2.02 KB 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. |