Skip to content
This repository was archived by the owner on Jul 24, 2021. It is now read-only.

Commit dcf55c4

Browse files
Merge pull request #1087 from joyent/ether/v3.2.1-fixes
v3.2.1 fixes
2 parents 545b54a + fec6139 commit dcf55c4

5 files changed

Lines changed: 57 additions & 17 deletions

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ including database connectivity information.
6666

6767
* `make run`
6868

69+
## Creating Local Credentials
70+
71+
First, you need to get a login token into the local database. We can do this by leveraging the
72+
knowledge that an encrypted password entry of `''` will match against all supplied inputs:
73+
74+
$ psql -U conch conch --command="insert into user_account (name, password, email) values ('me', '', 'your_email@joyent.com')"
75+
76+
Now, we use this email and password to generate a login token:
77+
78+
make run
79+
curl -i -H'Content-Type: application/json' --url http://127.0.0.1:5001/login -d '{"email":"your_email@joyent.com","password":"anything"}'
80+
81+
You will see output like this:
82+
83+
{"jwt_token":"eyJInR5cCI6Iwhargarbl.eyJl9pZCI6ImM1MGYwhargarbl.WV3uJEvg0bqInI9pEtl04ZZ8ECN4yQOSmehello"}
84+
85+
Save that token somewhere, such as in an environment variable or a file, for use in future API calls. You will include it in the "Authorization" header, for example:
86+
87+
curl -i --url https://staging.conch.joyent.us/user/me --header "Authorization: Bearer eyJInR5cCI6Iwhargarbl.eyJl9pZCI6ImM1MGYwhargarbl.WV3uJEvg0bqInI9pEtl04ZZ8ECN4yQOSmehello"
88+
6989
## Docker
7090

7191
### Compose

lib/Conch/Plugin/ClientVerification.pm

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ sub register ($self, $app, $config) {
3434
my $user_agent = $headers->user_agent;
3535

3636
if (my $conch_ui_version = $headers->header('X-Conch-UI')) {
37-
my ($major, $minor, $tiny, $rest) = $conch_ui_version =~ /^v(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?/;
37+
my ($major, $minor, $tiny, $rest) = $conch_ui_version =~ /^v(\d+)\.(\d+)(?:\.(\d+)(?:\.(\d+))?)?/;
3838
if (not $major or $major < 4) {
39-
$c->log->warn('Conch UI too old: requires at least 4.x');
40-
return $c->status(403);
39+
my $error = 'Conch UI too old: requires at least 4.x';
40+
$c->log->warn($error.' -- got major='.($major//'<undef>').', minor='.($minor//'<undef>'));
41+
return $c->status(403, { error => $error });
4142
}
4243
}
4344
elsif ($user_agent and $user_agent =~ /^conch shell/) {
@@ -47,8 +48,9 @@ sub register ($self, $app, $config) {
4748
elsif ($user_agent and $user_agent =~ /^Conch\/((\d+)\.(\d+)\.(\d+)) /) {
4849
my ($all, $major, $minor, $rest) = ($1, $2, $3, $4);
4950
if ($all eq '0.0.0' or $major < 3) {
50-
$c->log->warn('Conch Shell too old');
51-
return $c->status(403);
51+
my $error = 'Conch Shell too old';
52+
$c->log->warn($error.' -- got major='.($major//'<undef>').', minor='.($minor//'<undef>'));
53+
return $c->status(403, { error => $error });
5254
}
5355
}
5456
});

lib/Conch/Plugin/Logging.pm

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,20 @@ Logs the request and its response.
153153
headers => $req_headers,
154154
query_params => $c->req->query_params->to_hash,
155155
# no body_params: presently we do not permit application/x-www-form-urlencoded
156-
$verbose && !(ref $req_json eq 'HASH' and exists $req_json->{password})
157-
? ( body => $c->req->json // $c->req->text ) : (),
156+
!$verbose ? ()
157+
: !defined $req_json ? ( body => $c->req->text )
158+
: ref $req_json ne 'HASH' || !exists $req_json->{password} ? ( body => $req_json )
159+
: ( body => +{ $req_json->%*, password => '--REDACTED--' } ),
158160
},
159161
res => {
160162
headers => $res_headers,
161163
statusCode => $c->res->code,
162-
$c->res->code >= 400
163-
|| ($verbose && !(ref $res_json eq 'HASH' and grep /token/, keys $res_json->%*))
164-
? ( body => $c->res->json // $c->res->text ) : (),
164+
!$verbose && $c->res->code < 400 ? ()
165+
: !defined $res_json ? ( body => $c->res->text )
166+
: (ref $res_json ne 'HASH' || !grep /token/, keys $res_json->%*)
167+
? ( body => $res_json )
168+
: ( body => +{ $res_json->%*,
169+
map +($_ => '--REDACTED--'), grep /token/, keys $res_json->%* } ),
165170
},
166171
latency => int(1000 * $c->timing->elapsed('request_latency')),
167172
};

t/client-verification.t

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ $t->get_ok('/ping', { 'User-Agent' => 'Mozilla/5.0' })
1818

1919
$t->get_ok('/ping', { 'User-Agent' => 'Mozilla/5.0 Macintosh', 'X-Conch-UI' => 'v3.0.2.1-gdeadbeef' })
2020
->status_is(403)
21-
->log_warn_is('Conch UI too old: requires at least 4.x')
21+
->json_is({ error => 'Conch UI too old: requires at least 4.x' })
22+
->log_warn_is('Conch UI too old: requires at least 4.x -- got major=3, minor=0')
2223
->log_info_is(superhashof({
2324
req => superhashof({
2425
user => 'NOT AUTHED',
@@ -33,18 +34,23 @@ $t->get_ok('/ping', { 'User-Agent' => 'Mozilla/5.0 Macintosh', 'X-Conch-UI' => '
3334

3435
$t->get_ok('/ping', { 'User-Agent' => 'Mozilla/5.0 Macintosh', 'x-conch-ui' => 'v3.0.2.1-gdeadbeef' })
3536
->status_is(403)
36-
->log_warn_is('Conch UI too old: requires at least 4.x');
37+
->json_is({ error => 'Conch UI too old: requires at least 4.x' })
38+
->log_warn_is('Conch UI too old: requires at least 4.x -- got major=3, minor=0');
3739

3840
$t->get_ok('/ping', { 'User-Agent' => 'Mozilla/5.0 Macintosh', 'X-Conch-UI' => 'v4.0.0.3.gdeadbeef' })
3941
->status_is(200);
4042

43+
$t->get_ok('/ping', { 'User-Agent' => 'Mozilla/5.0 Macintosh', 'X-Conch-UI' => 'v4.1-0-gdeadbeef' })
44+
->status_is(200);
45+
4146
$t->get_ok('/ping', { 'User-Agent' => 'conch shell v1.11.11-v1.11-0-g0ad9598' })
4247
->status_is(403)
4348
->log_warn_is('Conch Shell too old');
4449

4550
$t->get_ok('/ping', { 'User-Agent' => 'Conch/0.0.0 ConchShell/blahblah...' })
4651
->status_is(403)
47-
->log_warn_is('Conch Shell too old');
52+
->json_is({ error => 'Conch Shell too old' })
53+
->log_warn_is('Conch Shell too old -- got major=0, minor=0');
4854

4955
$t->get_ok('/ping', { 'User-Agent' => 'Conch/3.12.0 ConchShell/blahblah...' })
5056
->status_is(200);

t/conch-log.t

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ sub add_test_routes ($t) {
724724
remotePort => ignore,
725725
headers => superhashof({}),
726726
query_params => {},
727-
# no body! that contains the password!!!
727+
body => { email => 'foo@example.com', password => '--REDACTED--' },
728728
},
729729
res => {
730730
headers => superhashof({}),
@@ -759,11 +759,13 @@ sub add_test_routes ($t) {
759759
remotePort => ignore,
760760
headers => superhashof({}),
761761
query_params => {},
762+
# Test::Conch::authenticate sets set_session -> true
763+
body => { email => 'conch@conch.joyent.us', password => '--REDACTED--', set_session => JSON::PP::true },
762764
},
763765
res => {
764766
headers => superhashof({}),
765767
statusCode => 200,
766-
# no body! that contains the JWT!!!
768+
body => { jwt_token => '--REDACTED--' },
767769
},
768770
},
769771
'dispatch line for /login success in verbose mode',
@@ -799,7 +801,12 @@ sub add_test_routes ($t) {
799801
res => {
800802
headers => superhashof({}),
801803
statusCode => 201,
802-
# no body! that contains the api token!!!
804+
body => {
805+
name => 'my api token',
806+
token => '--REDACTED--',
807+
(map +($_ => re(qr/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3,9}Z$/)), qw(created expires)),
808+
last_used => undef,
809+
},
803810
},
804811
},
805812
'dispatch line for creating a token in verbose mode does not contain the token string',
@@ -830,7 +837,7 @@ sub add_test_routes ($t) {
830837
remotePort => ignore,
831838
headers => superhashof({ Authorization => '--REDACTED--' }),
832839
query_params => {},
833-
# no body! that contains the password!!!
840+
body => { password => '--REDACTED--' },
834841
},
835842
res => {
836843
headers => superhashof({}),

0 commit comments

Comments
 (0)