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

Subscriptions: Correct v1.28.x regression allowing panic via un-named subscription operation #3738

Merged
merged 6 commits into from
Sep 4, 2023
Merged
Changes from 2 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
10 changes: 9 additions & 1 deletion apollo-router/src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Context {
// This method should be removed once we have a proper way to get the operation name.
self.entries
.get(OPERATION_NAME)
.map(|v| v.value().as_str().unwrap().to_string())
.and_then(|v| v.value().as_str().map(|s| s.to_string()))
}

/// Returns true if the context contains a value for the specified key.
Expand Down Expand Up @@ -307,6 +307,7 @@ impl Default for BusyTimer {

#[cfg(test)]
mod test {
use crate::context::OPERATION_NAME;
use crate::Context;

#[test]
Expand Down Expand Up @@ -370,4 +371,11 @@ mod test {
assert_eq!(c.get("one").unwrap(), Some(2));
assert_eq!(c.get("two").unwrap(), Some(3));
}

#[test]
fn operation_name_defaults_to_an_empty_string() {
let c = Context::new();
c.insert(OPERATION_NAME, Option::<String>::None).unwrap();
assert!(c.operation_name().is_none())
}
}