[Bps-public-commit] RT-Extension-NHD branch, master, updated. d05de3da0fc9504c2dc170d916179907af5b19b0
Ruslan Zakirov
ruz at bestpractical.com
Sun Sep 18 14:28:48 EDT 2011
The branch, master has been updated
via d05de3da0fc9504c2dc170d916179907af5b19b0 (commit)
via 62f773570c77547af25387456acd1def1bc8ed69 (commit)
via bbf792d82cd5fc4bd555e54cae2d2ba1bfb93db5 (commit)
via fe4972eca051b31e733763b7bc05930f01015d7e (commit)
via f09df1589c431df7b5fcddec73ad79be7f0fa8f8 (commit)
via c12edc8f3825b61f1bc1ff9ab9ca18741945b31a (commit)
via f42c1b91dcb40dc00c99ac7cf0f965137525e8a1 (commit)
via 311f879b33259705ea0e35754a2a1cb27dcaba8f (commit)
via 1625d671842a00564101ebaf77720f8960b1f720 (commit)
from fbcc54add3cd26263c1bb5975bfec0631eb325c9 (commit)
Summary of changes:
html/NoAuth/NHD/1.0/agreements/dhandler | 17 ++++++++++-------
lib/RT/Extension/NHD.pm | 11 ++++++++++-
lib/RT/Extension/NHD/Test/Web.pm | 4 +++-
lib/RT/NHD/Agreement.pm | 13 ++++++++++++-
spec_question.txt | 6 +++++-
t/web/agreement.t | 30 +++++++++++++++++++++++++++++-
6 files changed, 69 insertions(+), 12 deletions(-)
- Log -----------------------------------------------------------------
commit 1625d671842a00564101ebaf77720f8960b1f720
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sun Sep 18 22:09:20 2011 +0400
update spec questions and errata
diff --git a/spec_question.txt b/spec_question.txt
index f85dce9..5ebf6c1 100644
--- a/spec_question.txt
+++ b/spec_question.txt
@@ -1,4 +1,4 @@
-* should it /sharing only, can it be /xxx/sharing
+* should it be /sharing only, can it be /xxx/sharing?
* how to define point of entry, eg reciever URL?
@@ -9,3 +9,7 @@
* Why content type of requests and responses is not 'text/x-json'?
* is access_key of agreement mutable?
+
+* in section "Retrieving a Ticket Sharing Agreement"
+ code for "Method Not Allowed" HTTP status is wrong.
+ It should be 405, but it's 406.
commit 311f879b33259705ea0e35754a2a1cb27dcaba8f
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sun Sep 18 22:10:08 2011 +0400
check UUID using function we have
diff --git a/lib/RT/NHD/Agreement.pm b/lib/RT/NHD/Agreement.pm
index 093f2bc..8ade6e6 100644
--- a/lib/RT/NHD/Agreement.pm
+++ b/lib/RT/NHD/Agreement.pm
@@ -13,7 +13,7 @@ sub Table {'NHDAgreements'}
sub Load {
my $self = shift;
my $value = shift;
- if ( $value && $value =~ /^[0-9a-f]{40}$/i ) {
+ if ( RT::Extension::NHD->CheckUUID($value) ) {
return $self->LoadByCols( @_, UUID => $value );
}
return $self->SUPER::Load( $value, @_ );
commit f42c1b91dcb40dc00c99ac7cf0f965137525e8a1
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sun Sep 18 22:10:40 2011 +0400
on create is only valid status is pending
diff --git a/lib/RT/NHD/Agreement.pm b/lib/RT/NHD/Agreement.pm
index 8ade6e6..2af08c9 100644
--- a/lib/RT/NHD/Agreement.pm
+++ b/lib/RT/NHD/Agreement.pm
@@ -19,6 +19,17 @@ sub Load {
return $self->SUPER::Load( $value, @_ );
}
+sub Create {
+ my $self = shift;
+ my %args = @_;
+
+ my $status = $args{'Status'};
+ unless ( ($status||'') eq 'pending' ) {
+ return (undef, "New agreement must have 'pending' status");
+ }
+ return $self->SUPER::Create( %args );
+}
+
sub ValidateUUID { return RT::Extension::NHD->CheckUUID( $_[1] ) }
sub ValidateAccessKey { return RT::Extension::NHD->CheckUUID( $_[1] ) }
commit c12edc8f3825b61f1bc1ff9ab9ca18741945b31a
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sun Sep 18 22:11:56 2011 +0400
use 'Method Not Allowed' HTTP status code
diff --git a/html/NoAuth/NHD/1.0/agreements/dhandler b/html/NoAuth/NHD/1.0/agreements/dhandler
index 059c1f5..260248b 100644
--- a/html/NoAuth/NHD/1.0/agreements/dhandler
+++ b/html/NoAuth/NHD/1.0/agreements/dhandler
@@ -16,7 +16,7 @@ unless ( RT::Extension::NHD->CheckUUID( $duuid ) ) {
}
my $action = RT::Extension::NHD->WebRequestAction;
-return RT::Extension::NHD->BadWebRequest('Unprocessable Entity', "Unsupported method of the request")
+return RT::Extension::NHD->BadWebRequest('Method Not Allowed')
unless $action;
my $token = $r->headers_in->{'X-Ticket-Sharing-Token'};
diff --git a/lib/RT/Extension/NHD.pm b/lib/RT/Extension/NHD.pm
index dd5352e..f3ca300 100644
--- a/lib/RT/Extension/NHD.pm
+++ b/lib/RT/Extension/NHD.pm
@@ -40,6 +40,7 @@ my %HTTP_CODE = (
'Unauthorized' => 401,
'Forbidden' => 403,
'Not Found' => 404,
+ 'Method Not Allowed' => 405,
'Precondition Failed' => 412,
'Unprocessable Entity' => 422,
);
commit f09df1589c431df7b5fcddec73ad79be7f0fa8f8
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sun Sep 18 22:13:41 2011 +0400
uuid in arguments is optional on update/show
diff --git a/html/NoAuth/NHD/1.0/agreements/dhandler b/html/NoAuth/NHD/1.0/agreements/dhandler
index 260248b..26bc21f 100644
--- a/html/NoAuth/NHD/1.0/agreements/dhandler
+++ b/html/NoAuth/NHD/1.0/agreements/dhandler
@@ -19,6 +19,15 @@ my $action = RT::Extension::NHD->WebRequestAction;
return RT::Extension::NHD->BadWebRequest('Method Not Allowed')
unless $action;
+if ( $action ne 'create' ) {
+ $ARGS{'uuid'} = $uuid ||= $duuid;
+} elsif ( ($uuid||'') ne $duuid ) {
+ return RT::Extension::NHD->BadWebRequest(
+ 'Unprocessable Entity',
+ "UUIDs in the URI and body don't match"
+ );
+}
+
my $token = $r->headers_in->{'X-Ticket-Sharing-Token'};
return RT::Extension::NHD->BadWebRequest('Unauthorized')
unless $token;
@@ -50,12 +59,6 @@ if ( $agreement->id ) {
}
}
elsif ( $action eq 'create' ) {
- if (($uuid||'') ne $duuid ) {
- return RT::Extension::NHD->BadWebRequest(
- 'Unprocessable Entity',
- "UUIDs in the URI and body don't match"
- );
- }
my ($status, $msg) = $agreement->Create( %{ $agreement->FromJSON( \%ARGS ) } );
unless ( $status ) {
RT->Logger->error("Couldn't create NHD agreement: $msg");
commit fe4972eca051b31e733763b7bc05930f01015d7e
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sun Sep 18 22:14:36 2011 +0400
actually send JSON data in WebSendJSON
diff --git a/lib/RT/Extension/NHD.pm b/lib/RT/Extension/NHD.pm
index f3ca300..b69605e 100644
--- a/lib/RT/Extension/NHD.pm
+++ b/lib/RT/Extension/NHD.pm
@@ -80,6 +80,7 @@ sub WebSendJSON {
my $status = shift || 'OK';
$HTML::Mason::Commands::r->content_type( "text/x-json; charset=UTF-8" );
+ $HTML::Mason::Commands::m->out( $self->ToJSON( $data ) ) if $data;
return $self->GoodWebRequest( $status );
}
commit bbf792d82cd5fc4bd555e54cae2d2ba1bfb93db5
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sun Sep 18 22:14:57 2011 +0400
don't send data when GET things in tests
diff --git a/lib/RT/Extension/NHD/Test/Web.pm b/lib/RT/Extension/NHD/Test/Web.pm
index 72d15e4..292ff46 100644
--- a/lib/RT/Extension/NHD/Test/Web.pm
+++ b/lib/RT/Extension/NHD/Test/Web.pm
@@ -20,7 +20,9 @@ sub json_request {
my $self = shift;
my ($method, $uri, %args) = @_;
$uri = $self->rt_base_url .'NoAuth/NHD/1.0'. $uri;
- my $data = RT::Extension::NHD->ToJSON( delete $args{'data'} );
+ my $data;
+ $data = RT::Extension::NHD->ToJSON( delete $args{'data'} )
+ unless $method eq 'GET';
my %headers = %{ $args{'headers'}||{}};
%headers = (
%headers,
commit 62f773570c77547af25387456acd1def1bc8ed69
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sun Sep 18 22:16:25 2011 +0400
test show action and auth required
diff --git a/t/web/agreement.t b/t/web/agreement.t
index e95b5e6..fbb1247 100644
--- a/t/web/agreement.t
+++ b/t/web/agreement.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use RT::Extension::NHD::Test tests => 14;
+use RT::Extension::NHD::Test tests => 17;
use Digest::SHA1 qw(sha1_hex);
RT::Extension::NHD::Test->started_ok;
@@ -42,4 +42,27 @@ my $i = 0;
is( $agreement->Sender, 'http://hoster.example.com/sharing', 'correct value' );
is( $agreement->Receiver, 'http://rt.example.com/sharing', 'correct value' );
like( $agreement->AccessKey, qr{^[0-9a-f]{40}$}i, 'correct value' );
+
+ $response = $m->json_request( GET => '/agreements/'. $uuid );
+ is( $response->code, 401, 'auth required' );
+
+ $response = $m->json_request(
+ GET => '/agreements/'. $uuid,
+ headers => {
+ 'X-Ticket-Sharing-Token' => "$uuid:$access_key",
+ },
+ );
+ is( $response->code, 200, 'got agreement' );
+ is_deeply(
+ RT::Extension::NHD->FromJSON( $response->content ),
+ {
+ uuid => $uuid,
+ name => 'Test Company',
+ status => 'pending',
+ sender_url => 'http://hoster.example.com/sharing',
+ receiver_url => 'http://rt.example.com/sharing',
+ access_key => $access_key,
+ },
+ 'correct agreement',
+ );
}
commit d05de3da0fc9504c2dc170d916179907af5b19b0
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Sun Sep 18 22:27:54 2011 +0400
make sure we send WWW-Authenticate header
diff --git a/lib/RT/Extension/NHD.pm b/lib/RT/Extension/NHD.pm
index b69605e..3e8e06e 100644
--- a/lib/RT/Extension/NHD.pm
+++ b/lib/RT/Extension/NHD.pm
@@ -60,8 +60,15 @@ sub GoodWebRequest {
sub StopWebRequest {
my $self = shift;
my $info = shift;
+
my $code = $HTTP_CODE{ $info } or die "Bad status $info";
- $HTML::Mason::Commands::r->headers_out->{'Status'} = "$code $info";
+
+ my $r = $HTML::Mason::Commands::r;
+ $r->headers_out->{'Status'} = "$code $info";
+ if ( $code == 401 ) {
+ $r->headers_out->{'WWW-Authenticate'} = 'X-Ticket-Sharing';
+ }
+
if ( $code =~ /^2..$/ ) {
$HTML::Mason::Commands::m->abort( $code );
} else {
diff --git a/t/web/agreement.t b/t/web/agreement.t
index fbb1247..4d89e7d 100644
--- a/t/web/agreement.t
+++ b/t/web/agreement.t
@@ -3,7 +3,7 @@
use strict;
use warnings;
-use RT::Extension::NHD::Test tests => 17;
+use RT::Extension::NHD::Test tests => 18;
use Digest::SHA1 qw(sha1_hex);
RT::Extension::NHD::Test->started_ok;
@@ -45,6 +45,11 @@ my $i = 0;
$response = $m->json_request( GET => '/agreements/'. $uuid );
is( $response->code, 401, 'auth required' );
+ like(
+ $response->header('WWW-Authenticate'),
+ qr/\bX-Ticket-Sharing\b/,
+ 'WWW-Authenticate header is there'
+ );
$response = $m->json_request(
GET => '/agreements/'. $uuid,
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list