| index 6a52dfd5b..df35567dc 100644 |
| --- a/internal/grouprollaws/session_test.go |
| +++ b/internal/grouprollaws/session_test.go |
| @@ -683,3 +683,34 @@ func contextWithCancelAfter(d time.Duration) (context.Context, context.CancelFun |
| time.AfterFunc(d, cancel) |
| return c, cancel |
| } |
| + |
| +// Fable P3-3: a StartSession answer with a session id but no token or |
| +// stream URL cannot be attached to, so the plugin never runs; the session |
| +// it opened is cancelled at once (TerminateSession) before the error. |
| +func TestSessionWithoutTokenOrStreamIsCancelled(t *testing.T) { |
| + for name, answer := range map[string]string{ |
| + "no token": `{"SessionId":"` + testSession + `","StreamUrl":"` + testStream + `"}`, |
| + "no stream": `{"SessionId":"` + testSession + `","TokenValue":"` + testToken + `"}`, |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + dir := withFakePlugin(t, fakeControl{Body: statusBody}) |
| + a, rec := sessionAdapter(t, "eu-west-1") |
| + rec.responses["StartSession"] = []canned{{status: 200, body: answer}} |
| + var o observer |
| + _, err := a.Run(ctx, testIID, "status", grouproll.BoxArgs{}, o.seen) |
| + if u := uncertainKey(t, err); u.Key != "api" { |
| + t.Fatalf("error %#v, want Uncertain api", u) |
| + } |
| + if !reflect.DeepEqual(o.ids, []string{testSession}) { |
| + t.Fatalf("sessions reported %q", o.ids) |
| + } |
| + reqs := rec.requests() |
| + if len(reqs) != 2 || reqs[1].Action != "TerminateSession" || reqs[1].JSON["SessionId"] != testSession { |
| + t.Fatalf("requests %v, want StartSession then TerminateSession", rec.actions()) |
| + } |
| + if _, err := os.Stat(filepath.Join(dir, "fakeplugin-record.json")); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatal("the plugin ran without a token") |
| + } |
| + }) |
| + } |
| +} |