Dancer2-Plugin-Github-Webhook

 view release on metacpan or  search on metacpan

t/01-base.t  view on Meta::CPAN


{

    package MyTestApp;
    use Dancer2;
    use Dancer2::Plugin::Github::Webhook;

    set serializer => 'JSON';

    post '/' => require_github_webhook_secret sub { [1] };
    post '/a' => require_github_webhook_secret config->{'github-webhooks'}->{endpoint_a} => sub { [1] };
    post '/b' => require_github_webhook_secret config->{'github-webhooks'}->{endpoint_b} => sub { [1] };
    post '/c' => require_github_webhook_secret 'anotherverysecretsecret'                 => sub { [1] };

}

my $app = MyTestApp->to_app;

test_psgi $app, sub {
    my $cb = shift;

    {

t/01-base.t  view on Meta::CPAN

        my $content = JSON::to_json( { some => 'content', random => int(rand(1000)) * 11 } );
        require Digest::SHA;
        my $signature = 'sha1=' . Digest::SHA::hmac_sha1_hex( $content, 'anotherverysecretsecret' );
        my $req = HTTP::Request->new( POST => '/c' => [ 'X-Hub-Signature' => $signature ], $content );
        my $res = $cb->($req);
        is $res->code, 200, 'Correct signature is accepted';
        ok JSON::from_json( $res->content )->[0] eq '1', 'Correct signature is accepted';
    }

    {
        # correct signature, other endpoint
        
        my $content = JSON::to_json( { some => 'other', content => [qw/here in this array/] } );
        require Digest::SHA;
        my $signature = 'sha1=' . Digest::SHA::hmac_sha1_hex( $content, 'sk78fozuhv3efgv' );
        my $req = HTTP::Request->new( POST => '/a' => [ 'X-Hub-Signature' => $signature ], $content );
        my $res = $cb->($req);
        is $res->code, 200, 'Correct signature is accepted';
        ok JSON::from_json( $res->content )->[0] eq '1', 'Correct signature is accepted';
    }

t/lib/environments/base.yml  view on Meta::CPAN


plugins:
  Github::Webhook:
    secret: super!s3cret?

github-webhooks:
  endpoint_a: sk78fozuhv3efgv
  endpoint_b: 89Av34x!jdfl<



( run in 0.246 second using v1.01-cache-2.11-cpan-b61123c0432 )