Repository navigation
Expand file tree
/
Copy pathAccessTests.cs
More file actions
172 lines (147 loc) · 8.55 KB
/
Copy pathAccessTests.cs
File metadata and controls
172 lines (147 loc) · 8.55 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
using System.Globalization;
using System.Text.RegularExpressions;
using PythonScriptRunner.Panel.E2E.Tests.Infrastructure;
namespace PythonScriptRunner.Panel.E2E.Tests;
/// <summary>Spec 008: fixed login, expired session, roles and theme in the real panel.</summary>
public sealed partial class AccessTests(PostgresFixture postgres, BrokerFixture broker, PythonFixture python, BrowserFixture browser)
: PanelTest(postgres, broker, python, browser)
{
[Fact]
public async Task Spec008_AC17_FixedLogin_GoesToEntrar_RejectsAWrongPassword_ReturnsToTheRoute_AndLogsOut()
{
await StartAsync();
var page = await OpenAsync();
await GoToAsync(page, "execucoes");
await Expect(page).ToHaveURLAsync(App.UrlOf("entrar?volta=/execucoes"));
var form = page.Locator("form");
await form.FillLoginAsync(PanelUsers.Executor, "senha-errada");
await Expect(page.GetByText("Usuário ou senha inválidos.")).ToBeVisibleAsync();
await form.FillLoginAsync(null, PanelUsers.Password);
await Expect(page).ToHaveURLAsync(App.UrlOf("execucoes"));
var menu = page.Locator(".v-navigation-drawer");
await Expect(MenuItem(menu, "Execuções")).ToBeVisibleAsync();
await Expect(MenuItem(menu, "Agendamentos")).ToBeVisibleAsync();
await Expect(MenuItem(menu, "Auditoria")).ToHaveCountAsync(0);
await Expect(MenuItem(menu, "Administração")).ToHaveCountAsync(0);
await page.GetByTestId("user-menu").ClickAsync();
await page.GetByTestId("logout").ClickAsync();
await Expect(page).ToHaveURLAsync(new Regex("/psr/entrar"));
(await page.APIRequest.GetAsync(App.UrlOf("api/me"))).Status.ShouldBe(401);
}
[Fact]
public async Task Spec008_AC18_TheEleventhAttemptInAMinute_ShowsTheCountdown_AndTheLoginWorksWhenItEnds()
{
await StartAsync();
var page = await OpenAsync();
await GoToAsync(page, "entrar");
var form = page.Locator("form");
var submit = form.GetByRole(AriaRole.Button, new LocatorGetByRoleOptions { Name = "Entrar", Exact = true });
for (var i = 1; i <= 10; i++)
{
// Unknown users: the lockout of a user (5 failures) is not what this test is about.
await form.FillLoginAsync($"ninguem{i}", "senha-errada");
await Expect(form.GetByLabel("Senha")).ToHaveValueAsync(string.Empty);
}
await form.FillLoginAsync(PanelUsers.Author, PanelUsers.Password);
var countdown = page.GetByTestId("login-throttled");
await Expect(countdown).ToContainTextAsync(CountdownText());
await Expect(submit).ToBeDisabledAsync();
var seconds = int.Parse(CountdownText().Match(await countdown.InnerTextAsync()).Groups[1].Value, CultureInfo.InvariantCulture);
seconds.ShouldBeInRange(1, 60);
await Expect(countdown).Not.ToContainTextAsync($"em {seconds} s");
await Expect(countdown).ToBeHiddenAsync(new LocatorAssertionsToBeHiddenOptions { Timeout = 75_000 });
await Expect(submit).ToBeEnabledAsync();
await submit.ClickAsync();
await Expect(page).ToHaveURLAsync(App.Url.ToString());
}
[Fact]
public async Task Spec008_AC19_ExpiredSession_AsksTheSameUserInADialog_AndFinishesTheSave()
{
await StartAsync();
await App.SaveStageDraftAsync("eco", PanelScripts.Echo, [Scripts.Text("texto")], [Scripts.Text("texto")]);
var page = await OpenAsync(PanelUsers.Author);
await GoToAsync(page, "etapas/eco/editar");
await page.Locator("[data-testid=field-builder][data-kind=inputs]").GetByTestId("add-field").ClickAsync();
await Expect(page.GetByTestId("dirty")).ToBeVisibleAsync();
// The session ends (the cookie is gone, as when it expires): the save answers 401.
await page.Context.ClearCookiesAsync();
await page.GetByTestId("save").ClickAsync();
var dialog = page.Locator(".v-dialog").Filter(new LocatorFilterOptions { HasText = "Sua sessão expirou" });
await Expect(dialog).ToBeVisibleAsync();
await Expect(dialog.GetByLabel("Usuário")).ToHaveValueAsync(PanelUsers.Author);
await Expect(dialog.GetByLabel("Usuário")).Not.ToBeEditableAsync();
await dialog.FillLoginAsync(null, PanelUsers.Password);
await Expect(dialog).ToBeHiddenAsync();
await Expect(page.GetByTestId("dirty")).ToBeHiddenAsync();
var saved = await App.Host.Admin.GetStageDraftAsync("eco", Ct);
saved!.Data.Inputs.Select(f => f.Name).ShouldBe(["texto", "campo_2"]);
}
[Fact]
public async Task Spec008_AC10_Reader_SeesNoActionButtons_AndEditRoutesShowNoPermission()
{
await StartAsync(s => s.Worker = false);
await App.ImportFixtureAsync("calculo-progressao");
var run = await App.Host.Queue.EnqueuePipelineAsync("calculo-progressao", PanelScripts.Calculo, cancellationToken: Ct);
var executor = await OpenAsync(PanelUsers.Executor);
var reader = await OpenAsync(PanelUsers.Reader);
// What the reader must not see is there for the executor (no worker: the run stays queued and cancellable).
await GoToAsync(executor, $"execucoes/{run.RunId}");
await Expect(executor.GetByTestId("cancel-run")).ToBeVisibleAsync();
await GoToAsync(executor, "trilhas/calculo-progressao");
await Expect(executor.GetByTestId("run-pipeline")).ToBeVisibleAsync();
await GoToAsync(reader, $"execucoes/{run.RunId}");
await Expect(reader.GetByTestId("run-status")).ToBeVisibleAsync();
await Expect(reader.GetByTestId("cancel-run")).ToHaveCountAsync(0);
await GoToAsync(reader, "trilhas/calculo-progressao");
await Expect(reader.GetByTestId("versions-table")).ToBeVisibleAsync();
await ExpectNoneAsync(reader, "run-pipeline", "edit-pipeline", "delete-pipeline");
await GoToAsync(reader, "etapas");
await Expect(reader.Locator("[data-key=progressao-termos]")).ToBeVisibleAsync();
await ExpectNoneAsync(reader, "create", "import-zip");
await GoToAsync(reader, "etapas/progressao-termos");
await Expect(reader.GetByTestId("versions-table")).ToBeVisibleAsync();
await ExpectNoneAsync(reader, "edit-stage", "delete-stage");
await GoToAsync(reader, "agendamentos");
await Expect(reader.GetByTestId("schedules-table")).ToBeVisibleAsync();
await ExpectNoneAsync(reader, "create-schedule");
foreach (var path in new[] { "etapas/progressao-termos/editar", "trilhas/calculo-progressao/editar", "auditoria", "administracao" })
{
await GoToAsync(reader, path);
await Expect(reader.GetByRole(AriaRole.Heading, new PageGetByRoleOptions { Name = "Sem permissão" })).ToBeVisibleAsync();
}
}
[Fact]
public async Task Spec008_AC12_FollowsTheDarkSystemTheme_AndKeepsTheManualChoiceAfterReload()
{
await StartAsync(s => s.Worker = false);
await App.ImportFixtureAsync("calculo-progressao");
var page = await OpenAsync(PanelUsers.Reader, o => o.ColorScheme = ColorScheme.Dark);
await GoToAsync(page, "trilhas/calculo-progressao");
var app = page.Locator(".v-application");
await Expect(app).ToHaveClassAsync(new Regex(@"\bv-theme--dark\b"));
// The canvas controls and minimap follow the theme (Vue Flow styles them light by default).
await Expect(page.Locator(".vue-flow__minimap")).ToBeVisibleAsync();
var surface = await page.Locator(".flow-canvas").EvaluateAsync<string>("e => getComputedStyle(e).backgroundColor");
foreach (var part in new[] { ".vue-flow__controls-button", ".vue-flow__minimap" })
{
(await page.Locator(part).First.EvaluateAsync<string>("e => getComputedStyle(e).backgroundColor")).ShouldBe(surface, part);
}
await GoToAsync(page, string.Empty);
await page.GetByTestId("theme-menu").ClickAsync();
await page.GetByTestId("theme-light").ClickAsync();
await Expect(app).ToHaveClassAsync(new Regex(@"\bv-theme--light\b"));
await page.ReloadAsync();
await Expect(app).ToHaveClassAsync(new Regex(@"\bv-theme--light\b"));
}
private static ILocator MenuItem(ILocator menu, string text) =>
menu.GetByText(text, new LocatorGetByTextOptions { Exact = true });
private static async Task ExpectNoneAsync(IPage page, params string[] testIds)
{
foreach (var id in testIds)
{
await Expect(page.GetByTestId(id)).ToHaveCountAsync(0);
}
}
[GeneratedRegex(@"Tente de novo em (\d+) s")]
private static partial Regex CountdownText();
}