| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "reasonix/internal/control" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestRemoteModelConfirmationExpiresOnReconnectAndNewRuntime(t *testing.T) { |
| 9 | a := NewApp() |
| 10 | tab := &remoteTab{gen: 1, capabilities: map[string]bool{"model-application-v1": true}} |
| 11 | tab.routing.currentPath = "session" |
| 12 | a.remoteTabs = map[string]*remoteTab{"tab": tab} |
| 13 | d := &ModelApplicationDetails{RuntimeIdentity: "runtime", AppliedRevision: "a", DesiredRevision: "b", ConfirmationToken: "untrusted-source-token"} |
| 14 | bound := bindRemoteModelConfirmation(tab, 1, "session", d) |
| 15 | if bound.ConfirmationToken == d.ConfirmationToken { |
| 16 | t.Fatal("source supplied the host confirmation") |
| 17 | } |
| 18 | choice := control.ModelApplicationChoice{Mode: "applied_once", ExpectedRuntimeIdentity: "runtime", ExpectedAppliedRevision: "a", ExpectedDesiredRevision: "b", ConfirmationToken: bound.ConfirmationToken} |
| 19 | if err := a.validateRemoteModelConfirmation("tab", choice); err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | tab.gen = 2 |
| 23 | if err := a.validateRemoteModelConfirmation("tab", choice); err == nil { |
| 24 | t.Fatal("reconnect accepted old confirmation") |
| 25 | } |
| 26 | bindRemoteModelConfirmation(tab, 2, "session", d) |
| 27 | if err := a.validateRemoteModelConfirmation("tab", choice); err == nil { |
| 28 | t.Fatal("fresh status revived old confirmation") |
| 29 | } |
| 30 | choice.ConfirmationToken = tab.settings.details.ConfirmationToken |
| 31 | if err := a.validateRemoteModelConfirmation("tab", choice); err != nil { |
| 32 | t.Fatal(err) |
| 33 | } |
| 34 | d.RuntimeIdentity = "new-runtime" |
| 35 | bindRemoteModelConfirmation(tab, 2, "session", d) |
| 36 | if err := a.validateRemoteModelConfirmation("tab", choice); err == nil { |
| 37 | t.Fatal("replacement accepted old confirmation") |
| 38 | } |
| 39 | } |
| 40 |