Skip to content
Merged
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
50 changes: 45 additions & 5 deletions src/registry/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,16 @@
if !is_valid_project_id(request.id) {
return Ok(None);
}
// Always fetch the base project data
let data = self
.project_data(request.id)
.await?
.ok_or_else(|| RegistryError::Response("Project not found".to_string()))?;
// Always fetch the base project data. A missing project (registry
// returns 404) must surface as `Ok(None)` so callers can tell
// "project not found" apart from a transient registry error, matching
// the behaviour of `project_data_with_limits_impl`. Returning an `Err`

Check failure on line 295 in src/registry/client.rs

View workflow job for this annotation

GitHub Actions / spellcheck

[misspell] reported by reviewdog 🐶 "behaviour" is a misspelling of "behavior" Raw Output: ./src/registry/client.rs:295:15: "behaviour" is a misspelling of "behavior"
// here causes callers to treat an unknown project as a registry outage
// and fail open.
let data = match self.project_data(request.id).await? {
Some(data) => data,
None => return Ok(None),
};

let limits = match request.include_limits {
true => Some(
Expand Down Expand Up @@ -531,6 +536,41 @@
assert!(response.is_none());
}

#[tokio::test]
async fn project_data_with_returns_none_when_project_not_found() {
let project_id = "a".repeat(32);

let mock_server = MockServer::start().await;

// Registry returns 404 for a well-formed but unregistered project id.
Mock::given(method(Method::Get))
.and(path(format!("/internal/project/key/{project_id}")))
.respond_with(ResponseTemplate::new(404))
.mount(&mock_server)
.await;

let request = crate::project::ProjectDataRequest::new(&project_id).include_limits();

let response = RegistryHttpClient::with_config(
mock_server.uri(),
Some(mock_server.uri()),
"auth",
TEST_ORIGIN,
"st",
"sv",
Default::default(),
)
.unwrap()
.project_data_with(request)
.await
.unwrap();

// A missing project must be `Ok(None)`, not an `Err`: an `Err` makes
// callers treat an unknown project as a transient registry outage and
// fail open instead of rejecting the request.
assert!(response.is_none());
}

#[tokio::test]
async fn project_id_invalid_len() {
let project_id = "a".repeat(31);
Expand Down
Loading