camsigd tests, and a bug fix.

This commit is contained in:
Brad Fitzpatrick 2010-11-29 17:35:41 -08:00
parent f2259ba7d2
commit aacaa2239f
2 changed files with 45 additions and 1 deletions

View File

@ -38,7 +38,7 @@ func handleSign(conn http.ResponseWriter, req *http.Request) {
http_util.BadRequestError(conn, "json parameter lacks trailing '}'.")
return
}
trimmedJson = trimmedJson[0:len(trimmedJson)-2]
trimmedJson = trimmedJson[0:len(trimmedJson)-1]
cmd, err := exec.Run(
*gpgPath,

View File

@ -0,0 +1,44 @@
#!/usr/bin/perl
use strict;
use Test::More;
use FindBin;
use lib "$FindBin::Bin";
use CamsigdTest;
use JSON::Any;
use HTTP::Request::Common;
my $server = CamsigdTest::start();
ok($server, "Started the server") or BAIL_OUT("can't start the server");
my $ua = LWP::UserAgent->new;
my $j = JSON::Any->new;
my $json = $j->objToJson({ "camliVersion" => 1,
"foo" => "bar",
});
print "JSON: [$json]\n";
my $keyid = "26F5ABDA"; # test key
my $req = POST($server->root . "/camli/sig/sign",
"Authorization" => "Basic dGVzdDp0ZXN0", # test:test
Content => {
"json" => $json,
"keyid" => $keyid,
});
my $res = $ua->request($req);
ok($res, "got an HTTP response") or done_testing();
ok($res->is_success, "HTTP response is successful") or done_testing();
my $sjson = $res->content;
diag("Got signed: $sjson");
like($sjson, qr/camliSig/, "contains camliSig substring");
my $sobj = $j->jsonToObj($sjson);
is($sobj->{"foo"}, "bar", "key foo is still bar");
is($sobj->{"camliVersion"}, 1, "key camliVersion is still 1");
ok(defined $sobj->{"camliSig"}, "has camliSig key");
is(scalar keys %$sobj, 3, "total of 3 keys in signed object");
done_testing(8);