Commit e4faa4bf authored by Drew's avatar Drew

Modernize FISA with Caroline

parent b7394178
......@@ -19,67 +19,70 @@
import Foundation
import XCTest
import CarolineCore
import NaOH
@testable import FISAKit
class FISAFileTests: XCTestCase {
func testSave() {
var f = FISAFile()
let identity = Identity(description: "test", key: PublicKey())
f.identities.append(identity)
try! f.saveToFile("/tmp/test.fisa")
class FISAFileTests {
class Save: CarolineTest {
func test() throws {
let f = FISA.File(identity: CryptoBoxSecretKey(), description: "Foo")
try f.saveToFile("/tmp/test.fisa")
}
}
func testOpen() {
let identity = PublicKey()
var f = FISAFile()
f.identities.append(Identity(description: "test", key: identity))
f.secrets["test"] = "test"
try! f.saveToFile("/tmp/test.fisa")
let f2 = try! FISAFile(contentsOfFile: "/tmp/test.fisa", identity: identity)
XCTAssert(f2.secrets["test"] == "test")
class Open: CarolineTest {
func test() throws {
let key = CryptoBoxSecretKey()
var f = FISA.File(identity:key, description: "Foo")
f.secrets["test"] = "test"
try f.saveToFile("/tmp/test.fisa")
let f2 = try FISA.File(contentsOfFile: "/tmp/test.fisa", identity: key)
self.assert(f2.secrets["test"], equals: "test")
}
}
func testMultipleIdentities() {
let identity1 = Identity(description: "one", key: PublicKey())
let identity2 = Identity(description: "two", key: PublicKey())
var f = FISAFile()
f.identities.append(identity1)
f.identities.append(identity2)
f.secrets["test"] = "test"
try! f.saveToFile("/tmp/test.fisa")
let f2 = try! FISAFile(contentsOfFile: "/tmp/test.fisa", identity: identity2.key)
XCTAssert(f2.secrets["test"] == "test")
XCTAssert(f2.identities.count == 2)
class MultipleIdentities: CarolineTest {
func test() throws {
let identity1 = CryptoBoxSecretKey()
let identity2 = CryptoBoxSecretKey()
var f = FISA.File(identity: identity1, description: "one")
f.addIdentity(identity2.publicKey.bytes.base64, description: "two")
f.secrets["test"] = "test"
try! f.saveToFile("/tmp/test.fisa")
let f2 = try FISA.File(contentsOfFile: "/tmp/test.fisa", identity: identity2)
self.assert(f2.secrets["test"], equals: "test")
self.assert(f2.identities.count, equals: 2)
}
}
func testBadIdentity() {
var f = FISAFile()
let identity1 = Identity(description: "one", key: PublicKey())
let identity2 = Identity(description: "two", key: PublicKey())
f.identities.append(identity1)
f.identities.append(identity2)
f.secrets["test"] = "test"
try! f.saveToFile("/tmp/test.fisa")
do {
let _ = try FISAFile(contentsOfFile: "/tmp/test.fisa", identity: PublicKey())
XCTFail("Opened file")
class BadIdentity: CarolineTest {
func test() throws {
let identity1 = CryptoBoxSecretKey()
let identity2 = CryptoBoxSecretKey()
var f = FISA.File(identity: identity1, description: "one")
f.secrets["test"] = "test"
try! f.saveToFile("/tmp/test.fisa")
do {
let _ = try FISA.File(contentsOfFile: "/tmp/test.fisa", identity: identity2)
self.fail("Opened file")
}
catch FISAKitError.identityCantOpenFile { /* */ }
catch { self.fail(error) }
}
catch FISAKitError.IdentityCantOpenFile { /* */ }
catch { XCTFail("\(error)") }
}
func testIdentityAPI() {
//similar to the above tests, but with public APIs
var f = FISAFile()
let key1 = PublicKey()
let key2 = PublicKey()
class IdentityAPI: CarolineTest {
func test() throws {
var f = FISA.File(identity: CryptoBoxSecretKey(), description: "one")
let key2 = CryptoBoxSecretKey()
f.addIdentity(key2.publicKey.bytes.base64, description: "two")
self.assert(f.identities.count == 2)
try f.removeIdentity("two")
self.assert(f.identities.count == 1)
}
f.addIdentity(key1.bytes.base64, description: "one")
f.addIdentity(key2.bytes.base64, description: "two")
XCTAssert(f.identities.count==2)
try! f.removeIdentity("two")
XCTAssert(f.identities.count==1)
}
}
\ No newline at end of file
}
......@@ -45,7 +45,7 @@
:payloads [
{
:key "git"
:used-commit "08ac076e8578a2b0d7f204de72d954e99048f92b"
:used-commit "6489353d8c23214ffc6c8c4889fed8a874855c1b"
:pin false
}
]
......
......@@ -17,7 +17,6 @@
]
:tasks {
:kit {
:tool "atllbuild"
:sources ["FISAKit/**.swift"]
......@@ -26,6 +25,23 @@
:publish-product true
:dependencies ["pianissimo.default" "NaOH.default"]
:link-with-product ["pianissimo.a" "NaOH.a"]
:use-overlays ["NaOH.link"]
}
:gen-tests {
:tool "shell"
:script "caroline-static-tool --core ${collect_sources:kit-tests} > FISAKitTests/main.swift"
}
:kit-tests {
:tool "atllbuild"
:sources ["FISAKitTests/**.swift"]
:name "FISAKitTests"
:output-type "executable"
:publish-product true
:dependencies ["pianissimo.default" "NaOH.default" "Caroline.core" "kit" "gen-tests"]
:link-with-product ["pianissimo.a" "NaOH.a" "FISAKit.a" "CarolineCore.a"]
:use-overlays ["NaOH.link"]
:overlays {
:at.xcode-emit {
:include-with-user ["libsodium/libsodium/src/libsodium/include/"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment