Skip to content

Commit 730bb03

Browse files
alrsjefferai
authored andcommitted
Fix swallowed errors in builtin (hashicorp#2977)
1 parent 71fc373 commit 730bb03

File tree

9 files changed

+70
-1
lines changed

9 files changed

+70
-1
lines changed

builtin/audit/file/backend_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ import (
1515
func TestAuditFile_fileModeNew(t *testing.T) {
1616
modeStr := "0777"
1717
mode, err := strconv.ParseUint(modeStr, 8, 32)
18+
if err != nil {
19+
t.Fatal(err)
20+
}
1821

1922
path, err := ioutil.TempDir("", "vault-test_audit_file-file_mode_new")
23+
if err != nil {
24+
t.Fatal(err)
25+
}
26+
2027
defer os.RemoveAll(path)
2128

2229
file := filepath.Join(path, "auditTest.txt")

builtin/credential/approle/path_role_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ func TestAppRole_CIDRSubset(t *testing.T) {
6161

6262
secretIDData["cidr_list"] = "192.168.27.29/20,172.245.30.40/25,10.20.30.40/32"
6363
resp, err = b.HandleRequest(secretIDReq)
64+
if err != nil {
65+
t.Fatal(err)
66+
}
6467
if resp != nil && resp.IsError() {
6568
t.Fatalf("resp: %#v", resp)
6669
}

builtin/credential/aws/backend_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,9 @@ MlpCclZOR3JOOU4yZjZST2swazlLCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
616616
certReq.Operation = logical.ReadOperation
617617
// test read operation
618618
resp, err = b.HandleRequest(certReq)
619+
if err != nil {
620+
t.Fatal(err)
621+
}
619622
expectedCert := `-----BEGIN CERTIFICATE-----
620623
MIIC7TCCAq0CCQCWukjZ5V4aZzAJBgcqhkjOOAQDMFwxCzAJBgNVBAYTAlVTMRkw
621624
FwYDVQQIExBXYXNoaW5ndG9uIFN0YXRlMRAwDgYDVQQHEwdTZWF0dGxlMSAwHgYD
@@ -732,6 +735,9 @@ func TestBackend_parseAndVerifyRoleTagValue(t *testing.T) {
732735
Path: "role/abcd-123",
733736
Storage: storage,
734737
})
738+
if err != nil {
739+
t.Fatal(err)
740+
}
735741
if resp == nil {
736742
t.Fatalf("expected an role entry for abcd-123")
737743
}
@@ -1218,6 +1224,9 @@ func TestBackend_pathStsConfig(t *testing.T) {
12181224
stsReq.Operation = logical.ReadOperation
12191225
// test read operation
12201226
resp, err = b.HandleRequest(stsReq)
1227+
if err != nil {
1228+
t.Fatal(err)
1229+
}
12211230
expectedStsRole := "arn:aws:iam:account1:role/myRole"
12221231
if resp.Data["sts_role"].(string) != expectedStsRole {
12231232
t.Fatalf("bad: expected:%s\n got:%s\n", expectedStsRole, resp.Data["sts_role"].(string))

builtin/credential/aws/path_login.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,9 @@ func submitCallerIdentityRequest(method, endpoint string, parsedUrl *url.URL, bo
14231423
}
14241424
// we check for status code afterwards to also print out response body
14251425
responseBody, err := ioutil.ReadAll(response.Body)
1426+
if err != nil {
1427+
return nil, err
1428+
}
14261429
if response.StatusCode != 200 {
14271430
return nil, fmt.Errorf("received error code %s from STS: %s", response.StatusCode, string(responseBody))
14281431
}

builtin/credential/aws/path_login_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,17 @@ func TestBackend_pathLogin_getCallerIdentityResponse(t *testing.T) {
3232
expectedRoleArn := "arn:aws:sts::123456789012:assumed-role/RoleName/RoleSessionName"
3333

3434
parsedUserResponse, err := parseGetCallerIdentityResponse(responseFromUser)
35+
if err != nil {
36+
t.Fatal(err)
37+
}
3538
if parsed_arn := parsedUserResponse.GetCallerIdentityResult[0].Arn; parsed_arn != expectedUserArn {
3639
t.Errorf("expected to parse arn %#v, got %#v", expectedUserArn, parsed_arn)
3740
}
3841

3942
parsedRoleResponse, err := parseGetCallerIdentityResponse(responseFromAssumedRole)
43+
if err != nil {
44+
t.Fatal(err)
45+
}
4046
if parsed_arn := parsedRoleResponse.GetCallerIdentityResult[0].Arn; parsed_arn != expectedRoleArn {
4147
t.Errorf("expected to parn arn %#v; got %#v", expectedRoleArn, parsed_arn)
4248
}

builtin/credential/aws/path_role_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ func TestBackend_pathRoleMixedTypes(t *testing.T) {
463463
t.Fatalf("didn't allow creation of role resolving unique IDs")
464464
}
465465
resp, err = submitRequest("withInternalIdResolution", logical.ReadOperation)
466+
if err != nil {
467+
t.Fatal(err)
468+
}
466469
if resp.Data["bound_iam_principal_id"] != "FakeUniqueId1" {
467470
t.Fatalf("expected fake unique ID of FakeUniqueId1, got %q", resp.Data["bound_iam_principal_id"])
468471
}

builtin/credential/radius/path_login.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ func (b *backend) RadiusLogin(req *logical.Request, username string, password st
142142
var policies []string
143143
// Retrieve user entry from storage
144144
user, err := b.user(req.Storage, username)
145+
if err != nil {
146+
return policies, logical.ErrorResponse("could not retrieve user entry from storage"), err
147+
}
145148
if user == nil {
146149
// No user found, check if unregistered users are allowed (unregistered_user_policies not empty)
147150
if len(policyutil.SanitizePolicies(cfg.UnregisteredUserPolicies, false)) == 0 {

builtin/logical/aws/backend_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ func teardown() error {
196196
RoleName: aws.String(testRoleName), // Required
197197
}
198198
_, err := svc.DetachRolePolicy(attachment)
199+
if err != nil {
200+
log.Printf("[WARN] AWS DetachRolePolicy failed: %v", err)
201+
return err
202+
}
199203

200204
params := &iam.DeleteRoleInput{
201205
RoleName: aws.String(testRoleName),
@@ -206,9 +210,10 @@ func teardown() error {
206210

207211
if err != nil {
208212
log.Printf("[WARN] AWS DeleteRole failed: %v", err)
213+
return err
209214
}
210215

211-
return err
216+
return nil
212217
}
213218

214219
func testAccStepConfig(t *testing.T) logicaltest.TestStep {

builtin/logical/transit/backend_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,9 @@ func testConvergentEncryptionCommon(t *testing.T, ver int) {
754754
"context": "pWZ6t/im3AORd0lVYE0zBdKpX6Bl3/SvFtoVTPWbdkzjG788XmMAnOlxandSdd7S",
755755
}
756756
resp, err = b.HandleRequest(req)
757+
if err == nil {
758+
t.Fatal("expected error, got nil")
759+
}
757760
if resp == nil {
758761
t.Fatal("expected non-nil response")
759762
}
@@ -779,6 +782,9 @@ func testConvergentEncryptionCommon(t *testing.T, ver int) {
779782
"context": "pWZ6t/im3AORd0lVYE0zBdKpX6Bl3/SvFtoVTPWbdkzjG788XmMAnOlxandSdd7S",
780783
}
781784
resp, err = b.HandleRequest(req)
785+
if err != nil {
786+
t.Fatal(err)
787+
}
782788
if resp == nil {
783789
t.Fatal("expected non-nil response")
784790
}
@@ -788,6 +794,9 @@ func testConvergentEncryptionCommon(t *testing.T, ver int) {
788794
ciphertext1 := resp.Data["ciphertext"].(string)
789795

790796
resp, err = b.HandleRequest(req)
797+
if err != nil {
798+
t.Fatal(err)
799+
}
791800
if resp == nil {
792801
t.Fatal("expected non-nil response")
793802
}
@@ -813,6 +822,9 @@ func testConvergentEncryptionCommon(t *testing.T, ver int) {
813822
}
814823

815824
resp, err = b.HandleRequest(req)
825+
if err != nil {
826+
t.Fatal(err)
827+
}
816828
if resp == nil {
817829
t.Fatal("expected non-nil response")
818830
}
@@ -822,6 +834,9 @@ func testConvergentEncryptionCommon(t *testing.T, ver int) {
822834
ciphertext3 := resp.Data["ciphertext"].(string)
823835

824836
resp, err = b.HandleRequest(req)
837+
if err != nil {
838+
t.Fatal(err)
839+
}
825840
if resp == nil {
826841
t.Fatal("expected non-nil response")
827842
}
@@ -844,6 +859,9 @@ func testConvergentEncryptionCommon(t *testing.T, ver int) {
844859
"context": "qV4h9iQyvn+raODOer4JNAsOhkXBwdT4HZ677Ql4KLqXSU+Jk4C/fXBWbv6xkSYT",
845860
}
846861
resp, err = b.HandleRequest(req)
862+
if err != nil {
863+
t.Fatal(err)
864+
}
847865
if resp == nil {
848866
t.Fatal("expected non-nil response")
849867
}
@@ -853,6 +871,9 @@ func testConvergentEncryptionCommon(t *testing.T, ver int) {
853871
ciphertext5 := resp.Data["ciphertext"].(string)
854872

855873
resp, err = b.HandleRequest(req)
874+
if err != nil {
875+
t.Fatal(err)
876+
}
856877
if resp == nil {
857878
t.Fatal("expected non-nil response")
858879
}
@@ -878,6 +899,9 @@ func testConvergentEncryptionCommon(t *testing.T, ver int) {
878899
"context": "pWZ6t/im3AORd0lVYE0zBdKpX6Bl3/SvFtoVTPWbdkzjG788XmMAnOlxandSdd7S",
879900
}
880901
resp, err = b.HandleRequest(req)
902+
if err == nil {
903+
t.Fatal("expected error, got nil")
904+
}
881905
if resp == nil {
882906
t.Fatal("expected non-nil response")
883907
}
@@ -892,6 +916,9 @@ func testConvergentEncryptionCommon(t *testing.T, ver int) {
892916
"context": "pWZ6t/im3AORd0lVYE0zBdKpX6Bl3/SvFtoVTPWbdkzjG788XmMAnOlxandSdd7S",
893917
}
894918
resp, err = b.HandleRequest(req)
919+
if err != nil {
920+
t.Fatal(err)
921+
}
895922
if resp == nil {
896923
t.Fatal("expected non-nil response")
897924
}
@@ -901,6 +928,9 @@ func testConvergentEncryptionCommon(t *testing.T, ver int) {
901928
ciphertext7 := resp.Data["ciphertext"].(string)
902929

903930
resp, err = b.HandleRequest(req)
931+
if err != nil {
932+
t.Fatal(err)
933+
}
904934
if resp == nil {
905935
t.Fatal("expected non-nil response")
906936
}

0 commit comments

Comments
 (0)