# t/clean-embed.t # # Test LJ::CleanHTML::clean_embed. # # Authors: # Afuna # Jen Griffin # Andrea Nall # # Copyright (c) 2013 by Dreamwidth Studios, LLC. # # This program is free software; you may redistribute it and/or modify it under # the same terms as Perl itself. For a copy of the license, please reference # 'perldoc perlartistic' or 'perldoc perlgpl'. # use strict; use warnings; use Test::More tests => 189; BEGIN { $LJ::_T_CONFIG = 1; require "$ENV{LJHOME}/cgi-bin/ljlib.pl"; } use LJ::CleanHTML; use LJ::EmbedModule; use LJ::Test qw( temp_user ); note("Testing clean_embed (we provide the contents to be cleaned directly)"); { my ( $orig_post, $clean_post, $saved_post ); my $clean = sub { my ($opts) = @_; LJ::CleanHTML::clean_embed( \$orig_post, $opts ); }; note("no content"); $orig_post = qq{}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, "empty" ); note("simple object"); $orig_post = qq{}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, "basic " ); note(" and tags, params different case"); $orig_post = qq{}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, " and tags" ); note(" and tags"); $orig_post = qq{}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, " and tags" ); note(" and tags, keep never"); $orig_post = qq{}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, " and tags" ); note("object tag with data attribute"); $orig_post = qq{}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, "Drop the data attribute" ); note("script tag"); $orig_post = qq{}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, "}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, "}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, "}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, "}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, "}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, "}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, "}; $clean_post = qq{}; $clean->(); is( $orig_post, $clean_post, "end}; $clean->(); is( $orig_post, $clean_post, "(
)}; foreach ( ( # [ "title" # input (post) # post we save in the database # expected entry contents when we edit # expected contents when we view in a journal # contents of iframe we create # ], [ "no content", qq{}, qq{}, qq{}, qq{}, $invalid_embed ], [ "no embeddable content", qq{foo}, qq{foo}, qq{foo}, qq{foo}, $invalid_embed ], [ "empty embeddable content", qq{foo bar}, qq{foo bar}, qr{foo \s* bar}, qr{foo $iframe bar}, qr{\s*}, ], [ "dimensions: object tag with dimensions in percent", qq{}, qq{}, qq{}, qr{width="100%" height="100%"}, qq{}, ], [ "dimensions: object tag with mixed units for dimensions", qq{}, qq{}, qq{}, qr{width="80%" height="200"}, qq{}, ], [ "dimensions: object tag with dimensions in percent -- too big", qq{}, qq{}, qq{}, qr{width="100%" height="100%"}, qq{}, ], [ "object tag; no site-embed", qq{foo barbaz}, qq{foo baz}, qq{foo barbaz}, qr{foo ${iframe}baz}, qq{bar}, ], [ "object tag with site-embed", qq{foo baz}, qq{foo baz}, qq{foo baz}, qr{foo $iframe baz}, qq{}, ], [ "embed tag; no site-embed", qq{foo barbaz}, qq{foo baz}, qq{foo barbaz}, qr{foo ${iframe}baz}, qq{bar}, ], [ "embed tag with site-embed", qq{foo baz}, qq{foo baz}, qq{foo baz}, qr{foo $iframe baz}, qq{}, ], [ "iframe tag; no site-embed (untrusted)", qq{foo baz}, # wrap the iframe in a site-embed tag qq{foo baz}, # but nested site-embed won't display the untrusted content qq{foo baz}, qr{foo ${iframe}baz}, qq{}, ], [ "iframe tag with site-embed (untrusted)", qq{foo baz}, qq{foo baz}, qq{foo baz}, qr{foo $iframe baz}, qq{}, ], [ "iframe tag; no site-embed (trusted)", qq{foo baz}, # wrap the iframe in a site-embed qq{foo baz}, qq{foo baz}, # site-embed iframe qr{foo
\s*baz}, # ...which contains the nested iframe with a URL from a trusted source qq{}, ], [ "iframe tag with site-embed (trusted)", qq{foo baz}, # site-embed as normal qq{foo baz}, qq{foo baz}, # site-embed iframe qr{foo
\s*baz}, # ...which contains the nested iframe with a URL from a trusted source qq{}, ], # TODO: DANGER: EATS EVERYTHING PAST THE OPEN TAG [ "object tag left open; no site-embed", qq{foo blah bzzt}, qq{foo }, qq{foo }, qq{foo }, $invalid_embed ], [ "object tag left open in site-embed", qq{foo blah bzzt}, qq{foo bzzt}, qq{foo blah bzzt}, qr{foo $iframe bzzt}, qq{blah} ], # TODO: DANGER: EATS EVERYTHING PAST THE OPEN TAG [ "embed tag left open; no site-embed", qq{foo blah bzzt}, qq{foo }, qq{foo }, qq{foo }, $invalid_embed ], [ "embed tag left open in site-embed", qq{foo blah bzzt}, qq{foo bzzt}, qq{foo blah bzzt}, qr{foo $iframe bzzt}, qq{blah} ], # TODO: DANGER: EATS EVERYTHING PAST THE OPEN TAG [ "iframe tag left open; no site-embed (untrusted)", qq{foo }, qq{foo }, qq{foo }, qq{foo }, $invalid_embed ], # TODO: DANGER: EATS EVERYTHING PAST THE OPEN TAG [ "iframe tag left open in site-embed (untrusted)", qq{foo