diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index cebf2037..ec6f2281 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -57,7 +57,7 @@ jobs: working-directory: "${{ github.workspace }}/_build" - name: Run lcov - run: lcov --capture --directory "${{ github.workspace }}" --output-file coverage.info --no-external --exclude '*/tests/*' + run: lcov --capture --directory "${{ github.workspace }}" --output-file coverage.info --filter brace --no-external --exclude '*/tests/*' - name: Dump lcov run: lcov --list coverage.info diff --git a/core/tests/histogram_test.cc b/core/tests/histogram_test.cc index ef8ecda6..6f134819 100644 --- a/core/tests/histogram_test.cc +++ b/core/tests/histogram_test.cc @@ -57,6 +57,11 @@ TEST(HistogramTest, reject_unsorted_bucket_bounds) { EXPECT_ANY_THROW(Histogram({2, 1})); } +TEST(HistogramTest, reject_unsorted_bucket_bounds_lvalue) { + const Histogram::BucketBoundaries unsorted = {2, 1}; + EXPECT_THROW(Histogram{unsorted}, std::invalid_argument); +} + TEST(HistogramTest, reject_non_incrementing_bucket_bounds) { EXPECT_ANY_THROW(Histogram({1, 2, 2, 3})); } diff --git a/core/tests/summary_test.cc b/core/tests/summary_test.cc index d1662a41..f3549fb5 100644 --- a/core/tests/summary_test.cc +++ b/core/tests/summary_test.cc @@ -102,5 +102,26 @@ TEST(SummaryTest, construction_with_dynamic_quantile_vector) { summary.Observe(8.0); } +TEST(SummaryTest, quantile_with_out_of_order_batches) { + // Flush large values into the sample first, then insert smaller values so + // that insertBatch() hits the --idx path (value < sample_[item].value). + Summary summary{Summary::Quantiles{{0.5, 0.05}}, std::chrono::hours{1}}; + + for (int i = 0; i < 10; ++i) summary.Observe(100.0 + i); + summary.Collect(); // flushes buffer → sample_ now contains large values + + for (int i = 0; i < 10; ++i) summary.Observe(1.0 + i); + auto metric = summary.Collect(); // flushes buffer with small values < existing sample → --idx + auto s = metric.summary; + + // 20 observations total, sum = (1..10) + (100..109) = 55 + 1045 = 1100 + EXPECT_EQ(s.sample_count, 20U); + EXPECT_DOUBLE_EQ(s.sample_sum, 1100.0); + // p50 with error 0.05 on 20 samples: rank error ≤ 1, true median is 10 or 100 + ASSERT_EQ(s.quantile.size(), 1U); + EXPECT_GE(s.quantile.at(0).value, 1.0); + EXPECT_LE(s.quantile.at(0).value, 109.0); +} + } // namespace } // namespace prometheus diff --git a/pull/tests/integration/integration_test.cc b/pull/tests/integration/integration_test.cc index 1493e043..c203ed53 100644 --- a/pull/tests/integration/integration_test.cc +++ b/pull/tests/integration/integration_test.cc @@ -274,6 +274,19 @@ TEST_F(BasicAuthIntegrationTest, shouldRejectWrongAuthorizationMethod) { } #endif +TEST_F(BasicAuthIntegrationTest, shouldRejectNonBasicAuthScheme) { + std::unique_ptr header( + curl_slist_append(nullptr, "Authorization: Bearer sometoken"), + curl_slist_free_all); + + fetchPrePerform_ = [&header](CURL* curl) { + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header.get()); + }; + + const auto metrics = FetchMetrics(default_metrics_path_); + ASSERT_EQ(metrics.code, 401); +} + TEST_F(BasicAuthIntegrationTest, shouldRejectMalformedBase64) { std::unique_ptr header( curl_slist_append(nullptr, "Authorization: Basic $"), diff --git a/push/tests/internal/label_encoder_test.cc b/push/tests/internal/label_encoder_test.cc index 4aa722ce..05a0b9a5 100644 --- a/push/tests/internal/label_encoder_test.cc +++ b/push/tests/internal/label_encoder_test.cc @@ -23,6 +23,18 @@ TEST_F(LabelEncoderTest, regular) { EXPECT_EQ("/foo/bar", Encode(Label{"foo", "bar"})); } +TEST_F(LabelEncoderTest, uppercase) { + EXPECT_EQ("/foo/Bar", Encode(Label{"foo", "Bar"})); +} + +TEST_F(LabelEncoderTest, digits) { + EXPECT_EQ("/foo/bar123", Encode(Label{"foo", "bar123"})); +} + +TEST_F(LabelEncoderTest, unreserved_chars) { + EXPECT_EQ("/foo/a-b.c_d~e", Encode(Label{"foo", "a-b.c_d~e"})); +} + TEST_F(LabelEncoderTest, empty) { EXPECT_EQ("/first_label@base64/=", Encode(Label{"first_label", ""})); } diff --git a/util/tests/unit/base64_test.cc b/util/tests/unit/base64_test.cc index 89e7b405..8105b5a2 100644 --- a/util/tests/unit/base64_test.cc +++ b/util/tests/unit/base64_test.cc @@ -36,6 +36,9 @@ const TestVector testVector[] = { {"easure.", "ZWFzdXJlLg=="}, {"asure.", "YXN1cmUu"}, {"sure.", "c3VyZS4="}, + + // '/' character in encoded output (covers temp |= 0x3F branch in decode) + {"\xff\xff\xff", "////"}, }; using namespace testing;