[Rt-commit] rt branch, 5.0/rest2-base64-encode-attachment-content, created. rt-5.0.0-53-g1da2bc8059

Dianne Skoll dianne at bestpractical.com
Fri Oct 16 12:00:58 EDT 2020


The branch, 5.0/rest2-base64-encode-attachment-content has been created
        at  1da2bc8059a8601782c5692613c0907f88e7758f (commit)

- Log -----------------------------------------------------------------
commit 1da2bc8059a8601782c5692613c0907f88e7758f
Author: Dianne Skoll <dianne at bestpractical.com>
Date:   Fri Oct 16 11:53:22 2020 -0400

    Make GET .../REST2/attachment/:id base64-encode the Content field.

diff --git a/lib/RT/REST2/Resource/Attachment.pm b/lib/RT/REST2/Resource/Attachment.pm
index 40539fe238..f79c1a5240 100644
--- a/lib/RT/REST2/Resource/Attachment.pm
+++ b/lib/RT/REST2/Resource/Attachment.pm
@@ -50,6 +50,8 @@ package RT::REST2::Resource::Attachment;
 use strict;
 use warnings;
 
+use MIME::Base64;
+
 use Moose;
 use namespace::autoclean;
 
@@ -68,6 +70,14 @@ sub dispatch_rules {
     )
 }
 
+# Tweak serialize to base-64-encode Content
+around 'serialize' => sub {
+    my ($orig, $self) = @_;
+    my $data = $self->$orig(@_);
+    $data->{Content} = encode_base64($data->{Content}) if defined($data->{Content});
+    return $data;
+};
+
 __PACKAGE__->meta->make_immutable;
 
 1;
diff --git a/t/rest2/tickets.t b/t/rest2/tickets.t
index 837efd2992..2344011848 100644
--- a/t/rest2/tickets.t
+++ b/t/rest2/tickets.t
@@ -2,6 +2,7 @@ use strict;
 use warnings;
 use RT::Test::REST2 tests => undef;
 use Test::Deep;
+use MIME::Base64;
 
 # Test using integer priorities
 RT->Config->Set(EnablePriorityAsString => 0);
@@ -405,7 +406,7 @@ my ($ticket_url, $ticket_id);
     );
     is($res->code, 200);
     $content = $mech->json_response;
-    is($content->{Content}, 'Hello from hypermedia!');
+    is($content->{Content}, encode_base64('Hello from hypermedia!'));
     is($content->{ContentType}, 'text/plain');
 }
 
@@ -465,7 +466,7 @@ my ($ticket_url, $ticket_id);
     is($res->code, 200);
     $content = $mech->json_response;
     is($content->{Subject}, 'shh');
-    is($content->{Content}, '<i>(hello secret camera)</i>');
+    is($content->{Content}, encode_base64('<i>(hello secret camera)</i>'));
     is($content->{ContentType}, 'text/html');
 }
 

-----------------------------------------------------------------------


More information about the rt-commit mailing list