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

Fix Swift compilation issue when using Bool secrets #22

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ task default: %i[spec rubocop]

desc "Generates Swift source code and run its unit tests."
task :test_swift do
sh("bin/arkana --config-filepath spec/fixtures/swift-tests.yml")
sh("bin/arkana --config-filepath spec/fixtures/swift-tests.yml --dotenv-filepath spec/fixtures/.env.fruitloops")
Dir.chdir("tests/MySecrets") do
sh("swift test")
end
Expand Down
5 changes: 5 additions & 0 deletions lib/arkana/templates/arkana.swift.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public enum <%= @namespace %> {
element ^ cipher[offset % cipher.count]
}, as: UTF8.self)
}

static func decode(encoded: [UInt8], cipher: [UInt8]) -> Bool {
let stringValue: String = Self.decode(encoded: encoded, cipher: cipher)
return Bool(stringValue)!
}
}

public extension <%= @namespace %> {
Expand Down
20 changes: 20 additions & 0 deletions lib/arkana/templates/arkana_tests.swift.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,24 @@ final class <%= @namespace %>Tests: XCTestCase {
]
XCTAssertEqual(<%= @namespace %>.decode(encoded: encoded, cipher: salt), "<%= uuid_key %>")
}

func test_decodeTrueBoolValue_shouldDecode() {
<% bool_key = "true" %>
<% secret = generate_test_secret(key: bool_key) %>
let encoded: [UInt8] = [
<%= secret.encoded_value %>

]
XCTAssertTrue(<%= @namespace %>.decode(encoded: encoded, cipher: salt))
}

func test_decodeFalseBoolValue_shouldDecode() {
<% bool_key = "false" %>
<% secret = generate_test_secret(key: bool_key) %>
let encoded: [UInt8] = [
<%= secret.encoded_value %>

]
XCTAssertFalse(<%= @namespace %>.decode(encoded: encoded, cipher: salt))
}
}
4 changes: 4 additions & 0 deletions spec/fixtures/.env.fruitloops
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
DOTENV_KEY = "value from flavor dotenv"
BoolAsStringTrueKey = "true"
BoolAsStringFalseKey = "false"
BoolAsBoolTrueKey = true
BoolAsBoolFalseKey = false
5 changes: 5 additions & 0 deletions spec/fixtures/swift-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ result_path: 'tests'
swift_declaration_strategy: lazy var
should_generate_unit_tests: true
package_manager: spm
global_secrets:
- BoolAsStringTrueKey
- BoolAsStringFalseKey
- BoolAsBoolTrueKey
- BoolAsBoolFalseKey