From aacaa2239f67f27e14e88300b4de516791ffa1ae Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 29 Nov 2010 17:35:41 -0800 Subject: [PATCH] camsigd tests, and a bug fix. --- server/go/sigserver/sign.go | 2 +- server/go/sigserver/test/10-sign.t | 44 ++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 server/go/sigserver/test/10-sign.t diff --git a/server/go/sigserver/sign.go b/server/go/sigserver/sign.go index ebeb41a32..b9bd38086 100644 --- a/server/go/sigserver/sign.go +++ b/server/go/sigserver/sign.go @@ -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, diff --git a/server/go/sigserver/test/10-sign.t b/server/go/sigserver/test/10-sign.t new file mode 100644 index 000000000..a362a120f --- /dev/null +++ b/server/go/sigserver/test/10-sign.t @@ -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);