Skip to content
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

Add download entire period bundle feature #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions pkg/server/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,42 @@ func (s *retrieveServlet) retrieve(w http.ResponseWriter, r *http.Request) resul
return s.fail(log(ctx, nil).WithField("method", r.Method), w, "method not allowed", "", http.StatusMethodNotAllowed)
}

dateNumber64, err := strconv.ParseUint(vars["day"], 10, 32)
if err != nil {
return s.fail(log(ctx, err), w, "invalid day parameter", "", http.StatusBadRequest)
}
dateNumber := uint32(dateNumber64)
var startTimestamp time.Time
var endTimestamp time.Time
var dateNumber uint32

if vars["day"] == "00000" {

endDate := timemath.CurrentDateNumber() - 1
startDate := endDate - numberOfDaysToServe

dateNumber = endDate

startTimestamp = time.Unix(int64(startDate*86400), 0)
endTimestamp = time.Unix(int64((endDate+1)*86400), 0)

startTimestamp := time.Unix(int64(dateNumber*86400), 0)
endTimestamp := time.Unix(int64((dateNumber+1)*86400), 0)
} else {

dateNumber64, err := strconv.ParseUint(vars["day"], 10, 32)
if err != nil {
return s.fail(log(ctx, err), w, "invalid day parameter", "", http.StatusBadRequest)
}
dateNumber = uint32(dateNumber64)

startTimestamp = time.Unix(int64(dateNumber*86400), 0)
endTimestamp = time.Unix(int64((dateNumber+1)*86400), 0)

}

currentRSIN := pb.CurrentRollingStartIntervalNumber()
currentDateNumber := timemath.CurrentDateNumber()

if dateNumber == currentDateNumber {
return s.fail(log(ctx, err), w, "request for current date", "cannot serve data for current period for privacy reasons", http.StatusNotFound)
return s.fail(log(ctx, nil), w, "request for current date", "cannot serve data for current period for privacy reasons", http.StatusNotFound)
} else if dateNumber > currentDateNumber {
return s.fail(log(ctx, err), w, "request for future data", "cannot request future data", http.StatusNotFound)
return s.fail(log(ctx, nil), w, "request for future data", "cannot request future data", http.StatusNotFound)
} else if dateNumber < (currentDateNumber - numberOfDaysToServe) {
return s.fail(log(ctx, err), w, "request for too-old data", "requested data no longer valid", http.StatusGone)
return s.fail(log(ctx, nil), w, "request for too-old data", "requested data no longer valid", http.StatusGone)
}

// TODO: Maybe implement multi-pack linked-list scheme depending on what we hear back from G/A
Expand Down
38 changes: 36 additions & 2 deletions test/retrieve_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,40 @@ def test_retrieve_stuff
assert_keys(export, keys, region: 'CA', date_number: dn)
end

def test_all_keys
active_at = time_in_date('10:00', today_utc.prev_day(8))
two_days_ago = yesterday_utc.prev_day(1)
fourteen_days_ago = yesterday_utc.prev_day(13)
fifteen_days_ago = yesterday_utc.prev_day(14)

# Our retrieve endpoint returns keys SUBMITTED within the given period.
add_key(active_at: active_at, submitted_at: time_in_date("23:59:59", fifteen_days_ago), data: '1' * 16)
add_key(active_at: active_at, submitted_at: time_in_date("00:00", fourteen_days_ago), data: '2' * 16)
add_key(active_at: active_at, submitted_at: time_in_date("01:59:59", yesterday_utc), data: '3' * 16)
add_key(active_at: active_at, submitted_at: time_in_date("02:00", yesterday_utc), data: '4' * 16)
add_key(active_at: active_at, submitted_at: time_in_date("02:00", yesterday_utc), data: '5' * 16)
add_key(active_at: active_at, submitted_at: time_in_date("02:00", today_utc), data: '6' * 16)

rsin = rolling_start_interval_number(active_at)

resp = get_date("00000")
export = assert_happy_zip_response(resp)
keys = [tek(
rolling_start_interval_number: rsin,
transmission_risk_level: 8,
data: "3333333333333333",
), tek(
rolling_start_interval_number: rsin,
transmission_risk_level: 8,
data: "4444444444444444",
), tek(
rolling_start_interval_number: rsin,
transmission_risk_level: 8,
data: "5555555555555555",
),]
assert_keys(export, keys, region: 'CA', date_number: current_date_number - 15, date_range: 15)
Comment on lines +100 to +113
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxneuvians this assertion was missing in the original PR and it looks like there was an extra key in the keys array; the 2222222222222222 key was missing from the export.

Is that correct behaviour?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end

def test_period_bounds
active_at = time_in_date('10:00', today_utc.prev_day(8))
two_days_ago = yesterday_utc.prev_day(1)
Expand Down Expand Up @@ -258,9 +292,9 @@ def assert_valid_signature(signature, data)
key.dsa_verify_asn1(digest, signature)
end

def assert_keys(export, keys, region:, date_number:)
def assert_keys(export, keys, region:, date_number:, date_range: 1)
start_time = date_number * 86400
end_time = (date_number + 1) * 86400
end_time = (date_number + date_range) * 86400

assert_equal(
Covidshield::TemporaryExposureKeyExport.new(
Expand Down