Skip to content

Commit

Permalink
Merge pull request #179 from ipfs/sharness/basic-auth
Browse files Browse the repository at this point in the history
Sharness/basic auth
  • Loading branch information
hsanjuan committed Oct 17, 2017
2 parents 6e40610 + ce9fc18 commit 9c059a8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
5 changes: 3 additions & 2 deletions sharness/config/basic_auth/service.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"cluster_multiaddress": "/ip4/0.0.0.0/tcp/9096",
"api_listen_multiaddress": "/ip4/127.0.0.1/tcp/9094",
"basic_auth_credentials": {
"testuser": "testpass"
"testuser": "testpass",
"userwithoutpass": ""
},
"ipfs_proxy_listen_multiaddress": "/ip4/127.0.0.1/tcp/9095",
"ipfs_node_multiaddress": "/ip4/127.0.0.1/tcp/5001",
Expand All @@ -17,4 +18,4 @@
"replication_factor": -1,
"monitoring_interval_seconds": 15,
"allocation_strategy": "reposize"
}
}
5 changes: 4 additions & 1 deletion sharness/config/ssl-basic_auth/service.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"api_listen_multiaddress": "/ip4/127.0.0.1/tcp/9094",
"ssl_cert_file": "test-config/server.crt",
"ssl_key_file": "test-config/server.key",
"basic_auth_credentials": { "testuser" : "testpass" },
"basic_auth_credentials": {
"testuser" : "testpass",
"userwithoutpass": ""
},
"ipfs_proxy_listen_multiaddress": "/ip4/127.0.0.1/tcp/9095",
"ipfs_node_multiaddress": "/ip4/127.0.0.1/tcp/5001",
"state_sync_seconds": 60,
Expand Down
7 changes: 5 additions & 2 deletions sharness/t0042-basic-auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ test_expect_success "BasicAuth fails without credentials" '

test_expect_success "BasicAuth fails with bad credentials" '
id=`cluster_id`
{ test_must_fail ipfs-cluster-ctl --basic-auth "testuser:badpass" --force-http id; } | grep -A1 "401" | grep "Unauthorized"
{ test_must_fail ipfs-cluster-ctl --basic-auth "baduser:testpass" --force-http id; } | grep -A1 "401" | grep "Unauthorized"
{ test_must_fail ipfs-cluster-ctl --basic-auth "userwithoutpass:pass" --force-http id; } | grep -A1 "401" | grep "Unauthorized" &&
{ test_must_fail ipfs-cluster-ctl --basic-auth "testuser" --force-http id; } | grep -A1 "401" | grep "Unauthorized" &&
{ test_must_fail ipfs-cluster-ctl --basic-auth "testuser:badpass" --force-http id; } | grep -A1 "401" | grep "Unauthorized" &&
{ test_must_fail ipfs-cluster-ctl --basic-auth "baduser:testpass" --force-http id; } | grep -A1 "401" | grep "Unauthorized" &&
{ test_must_fail ipfs-cluster-ctl --basic-auth "baduser:badpass" --force-http id; } | grep -A1 "401" | grep "Unauthorized"
'

test_expect_success "BasicAuth over HTTP succeeds with CLI flag credentials" '
id=`cluster_id`
ipfs-cluster-ctl --basic-auth "userwithoutpass" --force-http id | grep -q "$id" &&
ipfs-cluster-ctl --basic-auth "testuser:testpass" --force-http id | grep -q "$id"
'

Expand Down
6 changes: 6 additions & 0 deletions sharness/t0043-ssl-basic-auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ test_expect_success "prerequisites" '
test_have_prereq IPFS && test_have_prereq CLUSTER
'

test_expect_success "ssl interaction fails with bad credentials" '
id=`cluster_id`
{ test_must_fail ipfs-cluster-ctl --no-check-certificate --basic-auth "testuser:badpass" id; } | grep -A1 "401" | grep "Unauthorized"
'

test_expect_success "ssl interaction succeeds" '
id=`cluster_id`
ipfs-cluster-ctl --no-check-certificate --basic-auth "userwithoutpass" id | egrep -q "$id" &&
ipfs-cluster-ctl --no-check-certificate --basic-auth "testuser:testpass" id | egrep -q "$id"
'

Expand Down

0 comments on commit 9c059a8

Please sign in to comment.