forked from rjbs/metabase-web
/
submit.t
120 lines (92 loc) · 3.88 KB
/
submit.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/perl
use strict;
use warnings;
use lib 't/lib';
use Test::More;
use Test::Metabase::Web::Config (allow_registration => 0);
use Test::Metabase::Client;
use Test::Metabase::StringFact;
use Metabase::User::Profile;
use Metabase::User::Secret;
diag "Test metabase located at " . Test::Metabase::Web::Config->storage_dir;
my $ok_profile;
my $ok_secret;
my $ok_password = 'aixuZuo8';
{
# We use this guy for submitting.
$ok_profile = Metabase::User::Profile->create({
email_address => 'jdoe@example.com',
full_name => 'John Doe',
}) or die "Couldn't create test profile";
$ok_profile->close;
$ok_secret = Metabase::User::Secret->new(
resource => $ok_profile->resource,
content => $ok_password,
) or die "Couldn't create test secret";
my $ok_client = Test::Metabase::Client->new({ profile => $ok_profile, secret => $ok_secret });
ok( Test::Metabase::Web::Config->gateway->public_librarian->store($ok_profile), "register profile" );
ok( Test::Metabase::Web::Config->gateway->public_librarian->extract($ok_profile->guid), "test retrieve profile" );
ok( Test::Metabase::Web::Config->gateway->private_librarian->store($ok_secret), "register secret" );
ok( Test::Metabase::Web::Config->gateway->private_librarian->extract($ok_secret->guid), "test retrieve secret" );
my $found = Test::Metabase::Web::Config->gateway->private_librarian->search(
'core.type' => 'Metabase-User-Secret',
'core.resource' => $ok_profile->resource->resource,
);
ok( scalar @$found, "search finds secret" );
my $fact = Test::Metabase::StringFact->new({
resource => 'cpan:///distfile/RJBS/Foo-Bar-1.23.tar.gz',
content => 'this power powered by power',
});
my $ok = eval { $ok_client->submit_fact($fact); 1 };
ok($ok, "resource created!") or diag $@;
my $fact_struct = $ok_client->retrieve_fact_raw($fact->guid);
ok( $fact_struct, "got a fact struct back" );
my $retr_fact = Test::Metabase::StringFact->from_struct($fact_struct);
is($retr_fact->guid, $fact->guid, "we got the same fact guid back");
is_deeply(
$retr_fact->content,
$fact->content,
"content is identical, too",
);
is($retr_fact->creator, $ok_profile->resource, 'fact has correct creator');
}
{
# We use this guy for failing to submit. He is not stored in the s_l
# and new registrations are disabled in the test Metabase Gateway
my $bad_profile = Metabase::User::Profile->create({
# resource => 'metabase:user:499DE666-1D7E-11DE-84B6-1B03411C7A0A',
# guid => '499DE666-1D7E-11DE-84B6-1B03411C7A0A',
email_address => 'gorp@example.com',
full_name => 'Gorp Zug',
});
my $bad_secret = Metabase::User::Secret->new(
resource => $bad_profile->resource,
content => 'dafdadfa'
);
$bad_profile->close;
my $bad_client = Test::Metabase::Client->new({ profile => $bad_profile, secret => $bad_secret });
my $fact = Test::Metabase::StringFact->new({
resource => 'cpan:///distfile/RJBS/Foo-Bar-1.23.tar.gz',
content => 'this power powered by power',
});
my $ok = eval { $bad_client->submit_fact($fact); 1 };
my $error = $@;
ok(! $ok, "resource rejected!");
like($error, qr/registration disabled/m, "rejected for the right reasons");
}
{
# We use this guy for failing to submit. He is in MB, but secret is wrong.
my $ok_struct = $ok_secret->as_struct;
$ok_struct->{content} =~ s/\Q$ok_password/bad-secret/;
my $bad_pw = Metabase::User::Secret->from_struct($ok_struct);
my $bad_client = Test::Metabase::Client->new({ profile => $ok_profile, secret => $bad_pw });
my $fact = Test::Metabase::StringFact->new({
resource => 'cpan:///distfile/RJBS/Foo-Bar-1.23.tar.gz',
content => 'this power powered by power',
});
my $ok = eval { $bad_client->submit_fact($fact); 1 };
my $error = $@;
ok(! $ok, "resource rejected!");
like($error, qr/user authentication failed/, "rejected for the right reasons");
}
done_testing;