2022-08-26 15:44:59 +00:00
|
|
|
// Copyright 2014 Google LLC. All rights reserved.
|
2014-02-14 23:21:05 +00:00
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2014-10-07 21:33:08 +00:00
|
|
|
#include "packager/media/base/http_key_fetcher.h"
|
2013-12-16 17:13:29 +00:00
|
|
|
|
2022-11-04 22:46:41 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "glog/logging.h"
|
|
|
|
#include "packager/status/status_test_util.h"
|
2013-12-16 17:13:29 +00:00
|
|
|
|
|
|
|
namespace {
|
2022-11-04 22:46:41 +00:00
|
|
|
const char kTestUrl[] = "https://httpbin.org/anything";
|
|
|
|
const char kTestUrl404[] = "https://httpbin.org/status/404";
|
|
|
|
const char kTestUrlWithPort[] = "https://httpbin.org:443/anything";
|
|
|
|
const char kTestUrlDelayTwoSecs[] = "https://httpbin.org/delay/2";
|
2023-05-01 23:56:46 +00:00
|
|
|
} // namespace
|
|
|
|
|
2023-07-13 22:55:36 +00:00
|
|
|
namespace shaka {
|
|
|
|
namespace media {
|
|
|
|
|
|
|
|
TEST(HttpFetcherTest, HttpGet) {
|
|
|
|
HttpKeyFetcher fetcher;
|
|
|
|
std::string response;
|
|
|
|
ASSERT_OK(fetcher.Get(kTestUrl, &response));
|
|
|
|
EXPECT_NE(std::string::npos, response.find("\"method\": \"GET\""));
|
2023-05-01 23:56:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-13 22:55:36 +00:00
|
|
|
TEST(HttpFetcherTest, HttpPost) {
|
|
|
|
HttpKeyFetcher fetcher;
|
|
|
|
std::string response;
|
|
|
|
ASSERT_OK(fetcher.Post(kTestUrl, "", &response));
|
|
|
|
EXPECT_NE(std::string::npos, response.find("\"method\": \"POST\""));
|
2013-12-16 17:13:29 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 22:46:41 +00:00
|
|
|
TEST(HttpKeyFetcherTest, HttpFetchKeys) {
|
2023-07-13 22:55:36 +00:00
|
|
|
HttpKeyFetcher fetcher;
|
|
|
|
std::string response;
|
|
|
|
ASSERT_OK(fetcher.FetchKeys(kTestUrl, "foo=62&type=mp4", &response));
|
|
|
|
EXPECT_NE(std::string::npos, response.find("\"foo=62&type=mp4\""));
|
2014-10-07 21:33:08 +00:00
|
|
|
}
|
2014-06-18 01:33:07 +00:00
|
|
|
|
2022-11-04 22:46:41 +00:00
|
|
|
TEST(HttpKeyFetcherTest, InvalidUrl) {
|
2023-07-13 22:55:36 +00:00
|
|
|
HttpKeyFetcher fetcher;
|
|
|
|
std::string response;
|
|
|
|
Status status = fetcher.FetchKeys(kTestUrl404, "", &response);
|
|
|
|
EXPECT_EQ(error::HTTP_FAILURE, status.error_code());
|
|
|
|
EXPECT_NE(std::string::npos, status.error_message().find("404"));
|
2013-12-16 17:13:29 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 22:46:41 +00:00
|
|
|
TEST(HttpKeyFetcherTest, UrlWithPort) {
|
2023-07-13 22:55:36 +00:00
|
|
|
HttpKeyFetcher fetcher;
|
|
|
|
std::string response;
|
|
|
|
ASSERT_OK(fetcher.FetchKeys(kTestUrlWithPort, "", &response));
|
2013-12-16 17:13:29 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 22:46:41 +00:00
|
|
|
TEST(HttpKeyFetcherTest, SmallTimeout) {
|
2021-08-04 18:56:44 +00:00
|
|
|
const int32_t kTimeoutInSeconds = 1;
|
2023-07-13 22:55:36 +00:00
|
|
|
HttpKeyFetcher fetcher(kTimeoutInSeconds);
|
|
|
|
std::string response;
|
|
|
|
Status status = fetcher.FetchKeys(kTestUrlDelayTwoSecs, "", &response);
|
|
|
|
EXPECT_EQ(error::TIME_OUT, status.error_code());
|
2014-06-18 01:33:07 +00:00
|
|
|
}
|
|
|
|
|
2022-11-04 22:46:41 +00:00
|
|
|
TEST(HttpKeyFetcherTest, BigTimeout) {
|
2023-07-13 22:55:36 +00:00
|
|
|
const int32_t kTimeoutInSeconds = 5;
|
|
|
|
HttpKeyFetcher fetcher(kTimeoutInSeconds);
|
|
|
|
std::string response;
|
|
|
|
Status status = fetcher.FetchKeys(kTestUrlDelayTwoSecs, "", &response);
|
|
|
|
EXPECT_OK(status);
|
2014-06-18 01:33:07 +00:00
|
|
|
}
|
|
|
|
|
2013-12-16 17:13:29 +00:00
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|