-
Notifications
You must be signed in to change notification settings - Fork 883
Add validation to ensure that settings.configs values are dictionaries, in order to prevent misuse #1547
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
Add validation to ensure that settings.configs values are dictionaries, in order to prevent misuse #1547
Changes from 9 commits
0cdd80d
58cdf9b
6af2709
5c164b2
d90866f
eac4831
8d90c4a
340b8e6
1b32082
70bf933
d9ca225
53968a5
c56b072
d65fc9e
cb2f605
54081ce
24040e7
9dc8405
ca9ed3e
6b9cc59
6f7592d
79d78ca
03bcec1
a792bcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| name: InvalidConfigsValueNonMapping | ||
|
|
||
| # This fixture is used to test the validation that ensures all values under `settings.configs` | ||
| # are mappings. `invalid_key0` and `invalid_key1` are not mapping, | ||
| # which should cause a SpecParsingError.invalidConfigsMappingFormat to be thrown. | ||
| settings: | ||
| configs: | ||
| invalid_key0: value0 | ||
| debug: | ||
| valid_key: value1 | ||
| invalid_key1: value2 |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,35 @@ | ||||||||
| import ProjectSpec | ||||||||
| import Testing | ||||||||
| import TestSupport | ||||||||
| import PathKit | ||||||||
|
|
||||||||
| struct invalidConfigsMappingFormatTests { | ||||||||
|
Ryu0118 marked this conversation as resolved.
Outdated
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Do we need it? Or do you remove it for other reason?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. even if we don't apply the
ref: https://developer.apple.com/documentation/testing/suite(_:_:)
yonaskolb marked this conversation as resolved.
Outdated
|
||||||||
| @Test("throws invalidConfigsMappingFormat error for non-dictionary configs entries") | ||||||||
| func testNonDictionaryConfigsEntries() throws { | ||||||||
|
Ryu0118 marked this conversation as resolved.
Outdated
|
||||||||
| let path = fixturePath + "invalid_configs_value_non_mapping.yml" | ||||||||
| let expectedError = SpecParsingError.invalidConfigsMappingFormat(keys: ["invalid_key0", "invalid_key1"]) | ||||||||
|
|
||||||||
| #expect(throws: EquatableErrorBox(expectedError)) { | ||||||||
| try perform(path: path) | ||||||||
| } | ||||||||
|
Ryu0118 marked this conversation as resolved.
Outdated
|
||||||||
| } | ||||||||
|
|
||||||||
| private func perform(path: Path) throws { | ||||||||
| do { | ||||||||
| _ = try Project(path: path) | ||||||||
| } catch let error as SpecParsingError { | ||||||||
| throw EquatableErrorBox(error) | ||||||||
| } catch { | ||||||||
| throw error | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // SpecParsingError does not conform to Equatable, so we wrap its description here | ||||||||
| private struct EquatableErrorBox: Error, Equatable { | ||||||||
| let description: String | ||||||||
|
|
||||||||
| init<E: Error & CustomStringConvertible>(_ error: E) { | ||||||||
| self.description = error.description | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
Uh oh!
There was an error while loading. Please reload this page.