Changeset 92 in bookmarks


Ignore:
Timestamp:
06/05/15 22:48:45 (10 years ago)
Author:
peter
Message:

issue #10: added basic test of the web app and the Bookmark class

To make the application testable, BookmarksApp now does not require a
config_file to be set, and can just be configured via a config hash in the
constructor. In addition, authentication and reverse proxy rewriting are now
conditionally enabled based on whether there is an auth and proxy_ip key in
the config, respecitvely.

Added Plack 1.0036 to the cpanfile dependencies, since that is the version that
contains Plack::Test.

Also fixed the Bookmarks::create_tables() method to load the
bookmarks.sql file from the correct location.

Location:
trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/cpanfile

    r80 r92  
    77requires 'Template'; 
    88requires 'Encode'; 
     9 
     10# web application 
     11requires 'Plack', '1.0036'; 
    912 
    1013# for opening the dbh handle 
  • trunk/lib/Bookmarks.pm

    r88 r92  
    3939    my $self = shift; 
    4040    require File::Slurp; 
    41     require FindBin; 
    42     my $table_definitions = File::Slurp::read_file("$FindBin::RealBin/bookmarks.sql"); 
     41    require File::Basename; 
     42    my $table_definitions = File::Slurp::read_file(File::Basename::dirname($INC{'Bookmarks.pm'}) . "/../bookmarks.sql"); 
    4343    $self->dbh->{sqlite_allow_multiple_statements} = 1; 
    4444    $self->dbh->do($table_definitions); 
  • trunk/lib/BookmarksApp.pm

    r81 r92  
    1717    my $self = shift; 
    1818 
    19     -e $self->config_file or die "Config file " . $self->config_file . " not found\n"; 
     19    my $config = $self->config; 
    2020 
    21     my $config = YAML::LoadFile($self->config_file); 
    22     $self->config($config); 
     21    # if the config_file is set, try to load the config from there 
     22    # note that currently, if there is a config_file and a config, 
     23    # all of the values in config are ignored in favor of those in 
     24    # the config_file 
     25    if ($self->config_file) { 
     26        -e $self->config_file or die "Config file " . $self->config_file . " not found\n"; 
     27        $config = YAML::LoadFile($self->config_file); 
     28        #TODO: merge the configs instead of overwriting? 
     29        $self->config($config); 
     30    } 
    2331 
    2432    my $router = router { 
     
    7583    $self->_app( 
    7684        builder { 
    77             enable_if { $_[0]->{REMOTE_ADDR} eq $config->{proxy_ip} } 'ReverseProxy'; 
     85            enable_if { $_[0]->{REMOTE_ADDR} eq $config->{proxy_ip} } 'ReverseProxy' 
     86                if $config->{proxy_ip}; 
    7887            enable_if { $_[0]->{REQUEST_METHOD} ne 'GET' } 'Auth::Digest', ( 
    7988                realm           => 'Bookmarks', 
     
    8190                password_hashed => 1, 
    8291                authenticator   => sub { $config->{digest_password} } 
    83             ); 
     92            ) if $config->{auth}; 
    8493            sub { $router->dispatch(shift); }; 
    8594        } 
Note: See TracChangeset for help on using the changeset viewer.