Repository navigation
fix(base): report a zero expiration for keys that never expire - #250
Merged
Merged
Conversation
david-santacruz-backblaze
suggested changes
Oct 30, 2026
david-santacruz-backblaze
left a comment
There was a problem hiding this comment.
Looks good mate, a few small things to check before:
- Live check: could we assert
key.Expires().IsZero()in an existing live test that creates a key, such asTestListBucketsWithKey? If not, a line in the PR saying that check was not run would do. - Comment on
keyExpiration: a short note on why0maps to the zero time andmillitimeis left alone would help the next reader. - Other
millitimecallers: #244 asks to note any with the same null case. Could you confirm the upload timestamps can't be null? - Nit:
5bb7db1is titledtest(...)but also touches the godoc and changelog.
3 tasks
Contributor
Author
|
@david-santacruz-backblaze Thanks, all four:
The branch is synced with main, and the description now has the live-check note, the |
david-santacruz-backblaze
approved these changes
Oct 30, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
b2_create_keyandb2_list_keysreturnexpirationTimestamp: nullfor an application key with no expiration.internal/b2typesdecodes it into anint64, so a null or absent value becomes0, andbasemapped it withmillitime(0)=time.Unix(0, 0).Key.Expires()therefore returned 1970-01-01 withIsZero() == false, so callers couldn't tell "never expires" from "expired in 1970".Fix
base/base.go: a small key-specific helper,keyExpiration, maps0to the zerotime.Timeand otherwise callsmillitime.CreateKeyandListKeysboth use it.millitimeitself is unchanged, because it also maps file upload timestamps, where0means something else.Key.Expires()(b2) andbase.Key.Expiressay the zero time means the key never expires, and that callers should checkIsZero(). NotUnix(), which is-62135596800for the zero time.Expires()to 1970-01-01, orUnix()to 0, should useIsZero().Null and absent
expirationTimestampboth decode to0inb2types.Key, and both mean "never expires", so both map to the zero time.b2types.AuthorizeAccountResponse.KeyExpirationhas the same null-to-0 pattern, but nothing reads it yet, so it's left alone.Verification
New tests in
base/key_expiration_test.goandb2/key_expiration_wire_test.gocover create and list withnull, with the field absent, and with a literal timestamp (1700000000123→2023-11-14T22:13:20.123Z).millitimefor keysCreateKey Expires = 1969-12-31 …, want zero time(8 assertions: null and absent, create and list, base and b2)CreateKey Expires = 0001-01-01 …, want 2023-11-14 22:13:20.123 +0000 UTCWith no B2 credentials set:
go test -race -count=3 -shuffle=on ./...,go vet ./...andmake cipass.Live check: the existing live tests that create a key without a lifetime now assert
Expires().IsZero()on the created key and on the same key returned byListKeys(b2/integration_test.go). They compile and run in the live CI job onmain; they were not run locally (no credentials).Other
millitimecallers (#244 asked to note any with the same null case): for upload, finish-large-file, copy, hide, get-file-info and unfinished-large-file timestamps, the B2 docs define no null or zero "no value" meaning. The one documented exception is virtual folder entries in delimiter listings (action: "folder",uploadTimestamp: 0), which still map to 1970. That is filed separately as #253.make ci(tail)Closes #244