webgui/t/Form/CsrfToken.t
Colin Kuskie 5e4db3adb4 Provide a framework for CSRF protection, with tests.
Add CSRF protection to Asset editSave, AssetManager, VersionTags and Group operations.
2009-07-06 16:58:57 +00:00

58 lines
1.6 KiB
Perl

#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Form;
use WebGUI::Form::CsrfToken;
use WebGUI::Session;
use HTML::Form;
use WebGUI::Form_Checking;
#The goal of this test is to verify that Zipcode form elements work
use Test::More; # increment this value for each test you create
my $session = WebGUI::Test->session;
# put your tests here
my $formClass = 'WebGUI::Form::CsrfToken';
my $numTests = 5;
plan tests => $numTests;
my ($header, $footer) = (WebGUI::Form::formHeader($session), WebGUI::Form::formFooter($session));
my $html = join "\n",
$header,
$formClass->new($session, {})->toHtml,
$footer;
my @forms = HTML::Form->parse($html, 'http://www.webgui.org');
##Test Form Generation
is(scalar @forms, 1, '1 form was parsed');
my @inputs = $forms[0]->inputs;
is(scalar @inputs, 1, 'The form has 1 input');
#Basic tests
my $input = $inputs[0];
is($input->name, 'webguiCsrfToken', 'Checking input name');
is($input->type, 'hidden', 'Checking input type');
is($input->value, $session->scratch->get('webguiCsrfToken'), 'Checking token value');