This repository has been archived by the owner on Feb 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from secrethub/release/v0.32.0
Release v0.32.0
- Loading branch information
Showing
24 changed files
with
475 additions
and
576 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,6 @@ import ( | |
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/secrethub/secrethub-go/internals/assert" | ||
) | ||
|
||
func TestValidateUsername(t *testing.T) { | ||
|
@@ -168,78 +166,3 @@ func TestValidateFullName(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestCreateUserRequest_Validate(t *testing.T) { | ||
cases := map[string]struct { | ||
req CreateUserRequest | ||
err error | ||
}{ | ||
"valid using password": { | ||
req: CreateUserRequest{ | ||
Username: "test.-_UserTestT", | ||
Email: "[email protected]", | ||
FullName: "Test Tester", | ||
Password: "hello world", | ||
}, | ||
err: nil, | ||
}, | ||
"valid using credential": { | ||
req: CreateUserRequest{ | ||
Username: "test.-_UserTestT", | ||
Email: "[email protected]", | ||
FullName: "Test Tester", | ||
Credential: &CreateCredentialRequest{ | ||
Type: CredentialTypeKey, | ||
Fingerprint: "88c9eae68eb300b2971a2bec9e5a26ff4179fd661d6b7d861e4c6557b9aaee14", | ||
Verifier: []byte("verifier"), | ||
}, | ||
}, | ||
err: nil, | ||
}, | ||
"invalid no password nor credential": { | ||
req: CreateUserRequest{ | ||
Username: "test.-_UserTestT", | ||
Email: "[email protected]", | ||
FullName: "Test Tester", | ||
}, | ||
err: ErrNoPasswordNorCredential, | ||
}, | ||
"invalid username": { | ||
req: CreateUserRequest{ | ||
Username: "", | ||
Email: "[email protected]", | ||
FullName: "Test Tester", | ||
Password: "hello world", | ||
}, | ||
err: ErrInvalidUsername, | ||
}, | ||
"invalid email": { | ||
req: CreateUserRequest{ | ||
Username: "test", | ||
Email: "notanemail", | ||
FullName: "Test Tester", | ||
Password: "hello world", | ||
}, | ||
err: ErrInvalidEmail, | ||
}, | ||
"invalid full name": { | ||
req: CreateUserRequest{ | ||
Username: "test", | ||
Email: "[email protected]", | ||
FullName: "", | ||
Password: "hello world", | ||
}, | ||
err: ErrInvalidFullName, | ||
}, | ||
} | ||
|
||
for name, tc := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
// Do | ||
err := tc.req.Validate() | ||
|
||
// Assert | ||
assert.Equal(t, err, tc.err) | ||
}) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -158,6 +158,7 @@ func UnexpectedError(err error) PublicError { | |
"an unexpected error occurred: %v\n\nTry again later or contact [email protected] if the problem persists", | ||
err, | ||
), | ||
err: err, | ||
} | ||
} | ||
|
||
|
@@ -190,6 +191,7 @@ type PublicError struct { | |
Namespace Namespace `json:"namespace,omitempty"` | ||
Code string `json:"code"` | ||
Message string `json:"message"` | ||
err error | ||
} | ||
|
||
// PublicError implements the error interface. | ||
|
@@ -221,6 +223,11 @@ func (e PublicError) Type() string { | |
return fmt.Sprintf("%s.%s", e.Namespace, e.Code) | ||
} | ||
|
||
// Unwrap returns the wrapped error if the PublicError represents an error wrapped as an UnexpectedError. | ||
func (e PublicError) Unwrap() error { | ||
return e.err | ||
} | ||
|
||
// PublicStatusError represents an http error. It contains an HTTP status | ||
// code and can be json encoded in an HTTP response. | ||
type PublicStatusError struct { | ||
|
@@ -263,3 +270,14 @@ func Equals(a PublicError, b error) bool { | |
} | ||
return a.Namespace == publicError.Namespace && a.Code == publicError.Code | ||
} | ||
|
||
// EqualsAPIError checks whether the given error has the namespace and code of the | ||
// given API error. The HTTP status code and error message aren't checked, so this | ||
// function is compatible with any changes to the message and HTTP status code. | ||
func EqualsAPIError(apiErr PublicStatusError, err error) bool { | ||
publicStatusError, ok := err.(PublicStatusError) | ||
if !ok { | ||
return false | ||
} | ||
return Equals(apiErr.PublicError, publicStatusError.PublicError) | ||
} |
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
Oops, something went wrong.