Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
271 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
package WWW::KeePassHttp::Entry; | ||
use 5.012; # //, strict, s//r | ||
use warnings; | ||
|
||
use MIME::Base64; | ||
use Crypt::Mode::CBC; | ||
use HTTP::Tiny; | ||
use JSON; # will use JSON::XS when available | ||
use Time::HiRes qw/gettimeofday sleep/; | ||
use MIME::Base64; | ||
use Carp; | ||
|
||
our $VERSION = '0.020'; # auto-populated from W:KPH | ||
|
||
=pod | ||
=head1 NAME | ||
WWW::KeePassHttp::Entry - Object-oriented access to an Entry retrived using WWW::KeePassHttp | ||
=head1 SYNOPSIS | ||
use WWW::KeePassHttp; | ||
my $kph = WWW::KeePassHttp->new(Key => $key); | ||
$kph->associate() unless $kph->test_associate(); | ||
my @entries = @${ $kph->get_logins($search_string) }; | ||
print $entry[0]->url; | ||
print $entry[0]->login; | ||
print $entry[0]->password; | ||
print $entry[0]->uuid; | ||
=head1 DESCRIPTION | ||
Object-oriented access to an Entry retrived using L<WWW::KeePassHttp>. | ||
=head1 DETAILS | ||
=over | ||
=item new | ||
my $entry = WWW::KeePassHttp::Entry->new( Url => 'https://github.com', Login => 'username', Password => 'password'); | ||
Creates a new Entry object. | ||
L<WWW::KeePassHttp> will do this for you when you grab entries. | ||
Or you can create a new Entry object when you want to L<set_login|WWW::KeePassHttp/set_login> | ||
Url, Login, and Password are all required to be defined. If you want those fields "empty", | ||
just use an emtpy string C<''> as the value. The Uuid will also be returned from an existing | ||
Entry from the database (but will be ignored ) | ||
=cut | ||
|
||
sub new | ||
{ | ||
my ($class, %opts) = @_; | ||
my $self = bless {}, $class; | ||
|
||
$self->{Url} = $opts{Url}; die "missing Url" unless defined $self->{Url}; | ||
$self->{Login} = $opts{Login}; die "missing Login" unless defined $self->{Login}; | ||
$self->{Password} = $opts{Password}; die "missing Password" unless defined $self->{Password}; | ||
$self->{Uuid} = $opts{Uuid} // ''; # Uuid is not required | ||
|
||
return $self; | ||
} | ||
|
||
=item url | ||
=item name | ||
print $entry->url(); | ||
print $entry->name(); # gives same result as ->url() | ||
$entry->url('https://new.url/'); # set new value | ||
The getter/setter for the Url of the Entry. Due to the nomenclature of the KeePassHttp plugin's | ||
C<get-logins> structure, the Url can also be accessed as the Name of the entry (since KeePassHttp | ||
uses the URL for both the URL field and the Title/Name field). | ||
=cut | ||
|
||
sub url | ||
{ | ||
my ($self, $val) = @_; | ||
$self->{Url} = $val if defined $val; | ||
return $self->{Url}; | ||
} | ||
|
||
*WWW::KeePassHttp::Entry::name = \&WWW::KeePassHttp::Entry::url; | ||
|
||
=item login | ||
print $entry->login(); | ||
$entry->login('https://new.url/'); # set new value | ||
The getter/setter for the Login of the Entry. | ||
=cut | ||
|
||
sub login | ||
{ | ||
my ($self, $val) = @_; | ||
$self->{Login} = $val if defined $val; | ||
return $self->{Login}; | ||
} | ||
|
||
=item password | ||
print $entry->password(); | ||
$entry->password('https://new.url/'); # set new value | ||
The getter/setter for the Password of the Entry. | ||
=cut | ||
|
||
sub password | ||
{ | ||
my ($self, $val) = @_; | ||
$self->{Password} = $val if defined $val; | ||
return $self->{Password}; | ||
} | ||
|
||
=item uuid | ||
print $entry->uuid(); # the UUID from the database entry | ||
The getter for the UUID of the Entry. | ||
=cut | ||
|
||
sub uuid | ||
{ | ||
my ($self, $val) = @_; | ||
$self->{Uuid} = $val if defined $val; | ||
return $self->{Uuid}; | ||
} | ||
|
||
=back | ||
=for comment END OF DETAILS | ||
=head1 AUTHOR | ||
Peter C. Jones C<E<lt>petercj AT cpan DOT orgE<gt>> | ||
Please report any bugs or feature requests | ||
thru the repository's interface at L<https://github.com/pryrt/WWW-KeePassHttp/issues>. | ||
=begin html | ||
<a href="https://metacpan.org/pod/WWW::KeePassHttp"><img src="https://img.shields.io/cpan/v/WWW-KeePassHttp.svg?colorB=00CC00" alt="" title="metacpan"></a> | ||
<a href="https://matrix.cpantesters.org/?dist=WWW-KeePassHttp"><img src="https://cpants.cpanauthors.org/dist/WWW-KeePassHttp.png" alt="" title="cpan testers"></a> | ||
<a href="https://github.com/pryrt/WWW-KeePassHttp/releases"><img src="https://img.shields.io/github/release/pryrt/WWW-KeePassHttp.svg" alt="" title="github release"></a> | ||
<a href="https://github.com/pryrt/WWW-KeePassHttp/issues"><img src="https://img.shields.io/github/issues/pryrt/WWW-KeePassHttp.svg" alt="" title="issues"></a> | ||
<a href="https://coveralls.io/github/pryrt/WWW-KeePassHttp?branch=main"><img src="https://coveralls.io/repos/github/pryrt/WWW-KeePassHttp/badge.svg?branch=main" alt="Coverage Status" /></a> | ||
<a href="https://github.com/pryrt/WWW-KeePassHttp/actions/"><img src="https://github.com/pryrt/WWW-KeePassHttp/actions/workflows/perl-ci.yml/badge.svg" alt="github perl-ci"></a> | ||
=end html | ||
=head1 COPYRIGHT | ||
Copyright (C) 2021 Peter C. Jones | ||
=head1 LICENSE | ||
This program is free software; you can redistribute it and/or modify it | ||
under the terms of either: the GNU General Public License as published | ||
by the Free Software Foundation; or the Artistic License. | ||
See L<http://dev.perl.org/licenses/> for more information. | ||
=cut | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# This will test "easy" errors -- ones that don't require mocked HTTP responses | ||
# | ||
use 5.012; # strict, // | ||
use warnings; | ||
use Test::More; | ||
use Test::Exception; | ||
|
||
BEGIN { | ||
use_ok 'WWW::KeePassHttp::Entry'; | ||
} | ||
|
||
my $e; | ||
|
||
# verify constructor working | ||
lives_ok { $e = WWW::KeePassHttp::Entry->new( Url => 'entry.url', Login => 'entry.login', Password => 'entry.pw') } 'entry success: normal entry'; | ||
isa_ok $e, 'WWW::KeePassHttp::Entry', 'Normal Entry'; | ||
|
||
# verify constructor working with UUID | ||
lives_ok { $e = WWW::KeePassHttp::Entry->new( Url => 'entry.url', Login => 'entry.login', Password => 'entry.pw', Uuid => 'entry.uuid') } 'entry success: entry with UUID'; | ||
isa_ok $e, 'WWW::KeePassHttp::Entry', 'Entry with UUID'; | ||
|
||
# verify setters | ||
is $e->url('https://new.url'), 'https://new.url', 'entry->url(): setter returns new value'; | ||
is $e->login('entry.username'), 'entry.username', 'entry->login(): setter returns new value'; | ||
is $e->password('entry.password'), 'entry.password', 'entry->password(): setter returns new value'; | ||
is $e->uuid('entry.uuid'), 'entry.uuid', 'entry->uuid(): setter returns new value'; | ||
|
||
# verify getters: by doing these in bulk after the bulk setters, it verifies they don't overwrite each other | ||
is $e->url(), 'https://new.url', 'entry->url(): getter returns same value'; | ||
is $e->login(), 'entry.username', 'entry->login(): getter returns same value'; | ||
is $e->password(), 'entry.password', 'entry->password(): getter returns same value'; | ||
is $e->uuid(), 'entry.uuid', 'entry->uuid(): getter returns same value'; | ||
|
||
# verify errors | ||
throws_ok { $e = WWW::KeePassHttp::Entry->new( Login => 'entry.login', Password => 'entry.pw') } qr/^\Qmissing Url/, 'entry error: missing URL'; | ||
throws_ok { $e = WWW::KeePassHttp::Entry->new( Url => 'entry.url', Password => 'entry.pw') } qr/^\Qmissing Login/, 'entry error: missing Login'; | ||
throws_ok { $e = WWW::KeePassHttp::Entry->new( Url => 'entry.url', Login => 'entry.login') } qr/^\Qmissing Password/, 'entry error: missing Password'; | ||
|
||
done_testing(16); |
Oops, something went wrong.