(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestEmbedOpen(t *testing.T) { |
| 15 | testmode.Expensive(t) |
| 16 | |
| 17 | adm := testadmin.NewWithOptionalRuntime(t, true) |
| 18 | |
| 19 | // First user is automatically a superuser. |
| 20 | _, u1Client := adm.NewUser(t) |
| 21 | u1 := testcli.New(t, adm, u1Client.Token) |
| 22 | |
| 23 | // Second user: regular, owns the org and project. |
| 24 | _, u2Client := adm.NewUser(t) |
| 25 | u2 := testcli.New(t, adm, u2Client.Token) |
| 26 | |
| 27 | // Third user: no access |
| 28 | _, u3Client := adm.NewUser(t) |
| 29 | u3 := testcli.New(t, adm, u3Client.Token) |
| 30 | |
| 31 | // u2 creates an org and deploys a project. |
| 32 | res := u2.Run(t, "org", "create", "embed-test") |
| 33 | require.Equal(t, 0, res.ExitCode, res.Output) |
| 34 | |
| 35 | tempDir := t.TempDir() |
| 36 | putFiles(t, tempDir, map[string]string{ |
| 37 | "rill.yaml": `olap_connector: duckdb`, |
| 38 | }) |
| 39 | res = u2.Run(t, "project", "deploy", "--interactive=false", "--org=embed-test", "--project=embed-project", "--path="+tempDir) |
| 40 | require.Equal(t, 0, res.ExitCode, res.Output) |
| 41 | |
| 42 | // Reconcile the deployment so it has a runtime host and instance. |
| 43 | adm.TriggerDeployment(t, "embed-test", "embed-project") |
| 44 | |
| 45 | // Superuser can get an embed URL for the project. |
| 46 | res = u1.Run(t, "sudo", "embed", "open", "embed-test", "embed-project", "--no-open", "--navigation") |
| 47 | require.Equal(t, 0, res.ExitCode, res.Output) |
| 48 | require.Contains(t, res.Output, "Open browser at:") |
| 49 | |
| 50 | // Normal user cannot get an embed URL for the project. |
| 51 | res = u3.Run(t, "sudo", "embed", "open", "embed-test", "embed-project", "--no-open", "--navigation") |
| 52 | require.NotEqual(t, 0, res.ExitCode) |
| 53 | require.Contains(t, res.Output, "does not have permission") |
| 54 | } |
| 55 | |
| 56 | func putFiles(t *testing.T, baseDir string, files map[string]string) { |
| 57 | t.Helper() |
nothing calls this directly
no test coverage detected