Skip to content

Commit c88e72f

Browse files
JayXonCQ Bot
authored andcommitted
[omaha-client] Don't overwrite cohort if it's missing from response.
Bug: 102304 Change-Id: I35043f3010605991e8bc6166694cbde78d7552d9 Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/690663 Fuchsia-Auto-Submit: Sen Jiang <[email protected]> Commit-Queue: Auto-Submit <[email protected]> Reviewed-by: Aaron Wood <[email protected]>
1 parent d20118c commit c88e72f

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/sys/pkg/lib/omaha-client/src/protocol.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,18 @@ impl Cohort {
4848
}
4949

5050
pub fn update_from_omaha(&mut self, omaha_cohort: Self) {
51-
// Do not overwrite cohort hint, because Omaha should never send cohort hint back.
52-
self.id = omaha_cohort.id;
53-
self.name = omaha_cohort.name;
51+
// From Omaha spec:
52+
// If this attribute is transmitted in the response (even if the value is empty-string),
53+
// the client should overwrite the current cohort of this app with the sent value.
54+
if omaha_cohort.id != None {
55+
self.id = omaha_cohort.id;
56+
}
57+
if omaha_cohort.hint != None {
58+
self.hint = omaha_cohort.hint;
59+
}
60+
if omaha_cohort.name != None {
61+
self.name = omaha_cohort.name;
62+
}
5463
}
5564

5665
/// A validation function to test that a given Cohort hint or name is valid per the Omaha spec:
@@ -84,6 +93,18 @@ mod tests {
8493
assert_eq!(None, cohort.name);
8594
}
8695

96+
#[test]
97+
fn test_cohort_update_from_omaha_none() {
98+
let mut cohort = Cohort {
99+
id: Some("id".to_string()),
100+
hint: Some("hint".to_string()),
101+
name: Some("name".to_string()),
102+
};
103+
let expected_cohort = cohort.clone();
104+
cohort.update_from_omaha(Cohort::default());
105+
assert_eq!(cohort, expected_cohort);
106+
}
107+
87108
#[test]
88109
fn test_valid_cohort_names() {
89110
assert!(Cohort::validate_name("some-channel"));

0 commit comments

Comments
 (0)