WWW-Authentik
view release on metacpan or search on metacpan
is( scalar @$found, 2, 'find_scope_mappings_by_scope' );
is( $found->[0]{scope_name}, 'openid', 'in the order the scopes were given' );
isa_ok( error_of { $api->find_scope_mappings_by_scope('no-such-scope') }, 'WWW::Authentik::Error::Validation', 'an unknown scope' );
my $mapping = $api->create_scope_mapping( { name => 'probe', scope_name => 'probe', expression => 'return {}' } );
ok( $mapping->{pk}, 'create_scope_mapping' );
is( $api->find_scope_mapping('probe')->{pk}, $mapping->{pk}, 'find_scope_mapping' );
is( $api->update_scope_mapping( $mapping->{pk}, { description => 'x' } )->{description}, 'x', 'update_scope_mapping' );
ok( $api->test_property_mapping( $mapping->{pk}, user => 1 )->{successful}, 'test_property_mapping' );
ok( $api->delete_scope_mapping( $mapping->{pk} ), 'delete_scope_mapping' );
};
subtest 'flows, stages and bindings' => sub {
my $flow = $api->create_flow( { name => 'Probe', slug => 'probe-flow', title => 'Probe', designation => 'authentication' } );
ok( $flow->{pk}, 'create_flow' );
is( $api->find_flow('probe-flow')->{title}, 'Probe', 'find_flow' );
like( $api->export_flow('probe-flow'), qr/\Aversion: 1/, 'export_flow gives the YAML as a string' );
ok( scalar @{ $api->stage_types }, 'stage_types' );
my $stage = $api->create_stage( password => { name => 'probe-password', backends => ['authentik.core.auth.InbuiltBackend'] } );
ok( $stage->{pk}, 'create_stage' );
is_deeply( error_of { $api->create_stage( user_login => { name => 'probe-password' } ) }->field_errors,
{ name => ['stage with this name already exists.'] }, 'a stage name is unique across the types' );
is( $api->find_stage('probe-password')->{pk}, $stage->{pk}, 'find_stage' );
is( $api->get_stage( password => $stage->{pk} )->{failed_attempts_before_cancel}, undef, 'get_stage through the typed endpoint' );
is( $api->update_stage( password => $stage->{pk}, { failed_attempts_before_cancel => 3 } )->{failed_attempts_before_cancel},
3, 'update_stage' );
# /stages/all/ can only be read
my $refused = error_of { $api->update_stage( all => $stage->{pk}, {} ) };
isa_ok( $refused, 'WWW::Authentik::Error::Validation', 'writing through /stages/all/' );
like( "$refused", qr{can only be read}, 'and says so' );
isa_ok( error_of { $api->get_stage( undef, 'x' ) }, 'WWW::Authentik::Error::Validation', 'without a type' );
my $binding = $api->create_binding( { target => $flow->{pk}, stage => $stage->{pk}, order => 20 } );
ok( $binding->{pk}, 'create_binding' );
is_deeply( error_of { $api->create_binding( { target => $flow->{pk}, stage => $stage->{pk}, order => 20 } ) }->field_errors,
{ non_field_errors => ['The fields target, stage, order must make a unique set.'] }, 'target, stage and order are unique' );
is( scalar @{ $api->list_bindings( target => $flow->{pk} ) }, 1, 'list_bindings by target' );
# authentik wants the UUID; a slug is the readable way in
is( scalar @{ $api->list_bindings( flow => 'probe-flow' ) }, 1, 'list_bindings by flow slug' );
is( scalar @{ $api->list_bindings( flow => $flow->{pk} ) }, 1, 'and by flow UUID' );
isa_ok( error_of { $api->list_bindings( flow => 'no-such-flow' ) },
'WWW::Authentik::Error::Validation', 'an unknown flow slug' );
is( $api->update_binding( $binding->{pk}, { order => 30 } )->{order}, 30, 'update_binding' );
is_deeply( $api->find_flow('probe-flow')->{stages}, [ $stage->{pk} ], 'the flow lists the stage' );
ok( $api->delete_binding( $binding->{pk} ), 'delete_binding' );
ok( $api->delete_stage( password => $stage->{pk} ), 'delete_stage' );
ok( $api->delete_flow('probe-flow'), 'delete_flow' );
};
subtest 'brands, certificates and blueprints' => sub {
ok( $api->current_brand, 'current_brand' );
ok( scalar @{ $api->list_brands }, 'list_brands' );
# the public view cannot be written back; the list is where the key is
my ( $brand ) = grep { $_->{default} } @{ $api->list_brands };
ok( $brand && $brand->{brand_uuid}, 'the list carries the brand_uuid' );
is( $api->update_brand( $brand->{brand_uuid}, { branding_title => 'Probe' } )->{branding_title}, 'Probe', 'update_brand' );
is( $api->find_certificate('authentik Self-signed Certificate')->{private_key_available}, 1, 'find_certificate' );
is( $api->find_certificate('nope'), undef, 'and nothing for an unknown one' );
my $blueprint = $api->create_blueprint( { name => 'probe', content => "version: 1\n" } );
is( $blueprint->{status}, 'unknown', 'a new blueprint has not run yet' );
is( $api->apply_blueprint( $blueprint->{pk} )->{status}, 'successful', 'apply_blueprint' );
is( $api->get_blueprint( $blueprint->{pk} )->{status}, 'successful', 'get_blueprint' );
ok( $api->delete_blueprint( $blueprint->{pk} ), 'delete_blueprint' );
};
done_testing;
( run in 1.319 second using v1.01-cache-2.11-cpan-8379b9b8ec2 )