-
Notifications
You must be signed in to change notification settings - Fork 6
handlers_test.go
: MOCK --> POSIX
#231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
# Conflicts: # internal/scti/handlers_test.go
# Conflicts: # internal/scti/handlers_test.go # Conflicts: # internal/scti/handlers_test.go
# Conflicts: # internal/scti/handlers_test.go # Conflicts: # internal/scti/handlers_test.go # Conflicts: # internal/scti/handlers_test.go
# Conflicts: # internal/scti/handlers_test.go
# Conflicts: # internal/scti/handlers_test.go
internal/scti/handlers_test.go
Outdated
server := setupTestServer(t, log, path.Join(prefix, "ct/v1/get-roots")) | ||
defer server.Close() | ||
|
||
t.Run("get-roots", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the t.Run
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woops, thanks
internal/scti/handlers_test.go
Outdated
|
||
func TestGetRoots(t *testing.T) { | ||
log := setupTestLog(t) | ||
server := setupTestServer(t, log, path.Join(prefix, "ct/v1/get-roots")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use types.GetRootsPath
? (bunch of other places in the PR too for this and the other paths)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can yeah - I did not do this intentionally because I see little benefits:
- I find the end result less readable
- this value is never going to change
internal/scti/handlers_test.go
Outdated
recorder := makeAddPrechainRequest(t, info.handlers, chain) | ||
if recorder.Code != test.want { | ||
t.Fatalf("addPrechain()=%d (body:%v); want %d", recorder.Code, recorder.Body, test.want) | ||
resp, err := http.Post(server.URL+"/ct/v1/add-pre-chain", "application/json", chain) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.Join(server.URL, types.AddPreChainPath)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Been there: I can't do this because server.URL contains http://
, which path.Join
does not understand, it will remove a forward slash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about url.JoinPath
?
func NewIssuerStorage(path string) (IssuersStorage, error) { | ||
// Does nothing if the dictory already exists. | ||
if err := os.MkdirAll(path, 0755); err != nil { | ||
return "", fmt.Errorf("failed to create path %q: %w", path, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need to wrap the err so the caller can determine something and react accordingly, or is %v
ok?
if strings.Contains(string(key), "/") { | ||
return "", fmt.Errorf("key %q cannot contain '/'", string(key)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just flagging that this is potentially brittle for future uses if e.g. you decide to use this storage with base64
encoding for keys down the line.
Some filesystems might get upset with other unusual characters like \0
, \\
, or :
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a package docstring, and expended this function docstring to highlight that this might not work on all filesystems, and that it's certainly not for production use.
} else { | ||
return fmt.Errorf("failed to read object %q: %w", objName, err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you don't need the indented else {}
here since you'll either return
or continue
if errors.Is(os.ErrNotExist)
.
return fmt.Errorf("failed to read object %q: %w", objName, err) | ||
} | ||
} else if bytes.Equal(f, kv.V) { | ||
klog.V(2).Infof("AddIssuersIfNotExist: object %q already exists, continuing", objName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
klog.V(2).Infof("AddIssuersIfNotExist: object %q already exists, continuing", objName) | |
klog.V(2).Infof("AddIssuersIfNotExist: object %q already exists with identical contents, continuing", objName) |
// - a POSIX Tessera storage driver | ||
// - a POSIX issuer storage system | ||
// - a BBolt deduplication database | ||
func newPosixStorageFunc(t *testing.T) storage.CreateStorage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Call this newPOSIXStorageFunc
?
https://google.github.io/styleguide/go/decisions#initialisms
internal/scti/handlers_test.go
Outdated
@@ -83,82 +79,129 @@ func (f *fixedTimeSource) Now() time.Time { | |||
return f.fakeTime | |||
} | |||
|
|||
// setupTest creates mock objects and contexts. Caller should invoke info.mockCtrl.Finish(). | |||
func setupTest(t *testing.T, pemRoots []string, signer crypto.Signer) handlerTestInfo { | |||
// setupTestLog creates test TesseraCT log using a POSIX backend. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// setupTestLog creates test TesseraCT log using a POSIX backend. | |
// setupTestLog creates a test TesseraCT log using the POSIX backend. |
internal/scti/handlers_test.go
Outdated
rejectExpired: false, | ||
roots := x509util.NewPEMCertPool() | ||
if err := roots.AppendCertsFromPEMFile(testRootPath); err != nil { | ||
t.Fatalf("failed to read trusted roots: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
t.Fatalf("failed to read trusted roots: %v", err) | |
t.Fatalf("Failed to read trusted roots: %v", err) |
if strings.Contains(string(key), "/") { | ||
return "", fmt.Errorf("key %q cannot contain '/'", string(key)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if strings.Contains(string(key), "/") { | |
return "", fmt.Errorf("key %q cannot contain '/'", string(key)) | |
if strings.Contains(string(key), os.PathSeparator) { | |
return "", fmt.Errorf("key %q cannot contain '%s'", string(key), os.PathSeparator) |
The /
in test needs to be updated if this is updated.
Towards #217, #5.
This PR reimplements
handlers_test.go
using a POSIX based log, rather than using a mock package.Precisely, this PR:
handlers_test.go
to initialise a log with a POSIX issuer storage, a POSIX Tessera backend, and a BBolt deduplication databaseFollowup PRs will add additional tests according to TODOs.