TestHarnessAuthMixin<T extends ApplicationChannel> class abstract

Use methods from this class to test applications that use AuthServer for authentication & authorization.

This class is mixed in to your TestHarness subclass to provide test utilities for applications that use OAuth2.

Methods from this class add client identifiers and authenticate users for the purpose of executing authenticated requests in your tests.

You must override authServer to return your application's AuthServer service, and application to return your harness' application.

This mixin is typically used with TestHarnessORMMixin and package:aquedart/managed_auth. Invoke addClient in TestHarnessORMMixin.seed to add OAuth2 clients that will survive TestHarnessORMMixin.resetData.

    class Harness extends TestHarness<MyChannel>
      with TestHarnessManagedAuthMixin<MyChannel>, TestHarnessORMMixin {
        Agent publicAgent;

        @override
        AuthServer get authServer => channel.authServer;

        @override
        Application<T> get application => channel.application;

        Future seed() async {
          // Create a new OAuth2 client that users can authenticate with
          publicAgent = await addClient("com.public.client");
        }
    }
Implemented types

Constructors

TestHarnessAuthMixin()

Properties

agent Agent?
The default Agent that makes requests to the application being tested.
getter/setter pairinherited
application → Application<T>?
The application being tested.
no setterinherited
authServer → AuthServer?
Must override to return authServer of application under test.
no setter
channel → T
The channel of the running application.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
options ↔ ApplicationOptions
Application options for the application being tested.
getter/setter pairinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

addClient(String id, {String? secret, String? redirectUri, List<String>? allowedScope}) Future<Agent>
Creates a new OAuth2 client identifier and returns an Agent that makes requests on behalf of that client.
afterStart() Future
Override this method to provide post-startup behavior for the application under test.
inherited
beforeStart() Future
Override this method to provide configuration for the application under test.
inherited
install({bool restartForEachTest = false}) → void
Installs this handler to automatically start before tests begin running,
inherited
loginUser(Agent fromAgent, String username, String password, {List<String>? scopes}) Future<Agent>
Authenticates a user for username and password.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onSetUp() Future
Override this method to register a setUp closure.
inherited
onTearDown() Future
Override this method to register a tearDown closure.
inherited
start() Future
Initializes a test application and starts it.
inherited
stop() Future
Stops the test application from running.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited