diff --git a/pkg/server/retrieve.go b/pkg/server/retrieve.go index e83bb87..345f908 100644 --- a/pkg/server/retrieve.go +++ b/pkg/server/retrieve.go @@ -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 diff --git a/test/retrieve_test.rb b/test/retrieve_test.rb index d1030ea..d6ee992 100644 --- a/test/retrieve_test.rb +++ b/test/retrieve_test.rb @@ -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) + 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) @@ -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(