microsoft / PowerApps-TestEngine

MIT License
108 stars 33 forks source link

[Feature]: Storage State Authentication Provider #389

Open Grant-Archibald-MS opened 2 weeks ago

Grant-Archibald-MS commented 2 weeks ago

Is your feature request related to a problem? Please describe.

There is a need to provide headless authentication to execute tests in environments where one or more factors of authentication are required. The key problem is how to preserve the session state so that interactive or headless tests can be run on interactive desktop environments or headless CI/CD tests.

Describe the solution you'd like

The provider should have the ability to save and load the storage state for web based tests using the underlying Playwright browser subsystem of Test Engine.

It should provide a method to default the username from the userProfile name environment variable defined in the test settings.

The provider should observe the login process and detect a successful login by observing the network request/response for known patterns when integrating with Microsoft Entra for authentication. The detection should allow for cases like expiry of tokens and fail the test with descriptive error messages

It should also handle common error cases such as the user not being authenticated for the environment or not being licensed.

If scenarios like not authenticated for the environment or not licensed for the desired URL are found, it should update the ITestState so that the provider (e.g., Canvas App or Model Driven App) can be aware of valid login but invalid security setup.

The results of detected patterns should be made available to the Power Fx engine know of that state so that a test case can be created that validates that the user cannot access the desired location because of license or environment permissions.

The saved storage stage should be encrypted using the current users security context or reversable encryption key. If an invalid or encryption key is applied it should apply a backoff scheme for retry

The state file should be able to support login for multiple storage state files for different user profile values.

Describe alternatives you've considered

Samples to save the storage state

var context = await browser.NewContextAsync(); var page = await context.NewPageAsync(); await page.GotoAsync("https://example.com"); // Perform login actions await context.StorageStateAsync(new BrowserContextStorageStateOptions { Path = "state.json" });

Sample to load state

var context = await browser.NewContextAsync(new BrowserNewContextOptions { StorageStatePath = "state.json" }); var page = await context.NewPageAsync(); await page.GotoAsync("https://example.com");

Additional context?

No response

Grant-Archibald-MS commented 3 days ago

Changes now merged into https://github.com/microsoft/PowerApps-TestEngine/tree/integration

Grant-Archibald-MS commented 3 days ago

Keeping feature request open as the user authentication provider still was items to complete before can close