Skip to content
Draft
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
19 changes: 19 additions & 0 deletions .github/workflows/swift-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: swift-format

on:
pull_request:
paths:
- '.github/workflows/swift-format.yml'
- '.swift-format'
- '**/*.swift'

permissions:
contents: read

jobs:
swift-format:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Lint with swift-format
run: xcrun swift-format lint --strict -r -p .
21 changes: 0 additions & 21 deletions .github/workflows/swiftlint.yml

This file was deleted.

12 changes: 12 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"lineLength": 200,
"indentation": {
"spaces": 4
},
"multiElementCollectionTrailingCommas": false,
"rules": {
"AlwaysUseLowerCamelCase": false,
"ReplaceForEachWithForLoop": false
}
}
12 changes: 0 additions & 12 deletions .swiftlint.yml

This file was deleted.

23 changes: 0 additions & 23 deletions PPPC Utility.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,6 @@
isa = PBXNativeTarget;
buildConfigurationList = 6EC409EA214D65BD00BE4F17 /* Build configuration list for PBXNativeTarget "PPPC Utility" */;
buildPhases = (
49DB95D624991AA800F433CA /* SwiftLint */,
6EC409D6214D65BC00BE4F17 /* Sources */,
6EC409D7214D65BC00BE4F17 /* Frameworks */,
6EC409D8214D65BC00BE4F17 /* Resources */,
Expand Down Expand Up @@ -466,28 +465,6 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
49DB95D624991AA800F433CA /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = SwiftLint;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export PATH=\"$PATH:/opt/homebrew/bin\"\n\nif which swiftlint >/dev/null; then\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
5F95AE172315A6AD002E0A22 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
39 changes: 22 additions & 17 deletions PPPC UtilityTests/Helpers/TCCProfileBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class TCCProfileBuilder: NSObject {
// MARK: - build testing objects

func buildTCCPolicy(allowed: Bool?, authorization: TCCPolicyAuthorizationValue?) -> TCCPolicy {
var policy = TCCPolicy(identifier: "policy id", codeRequirement: "policy code req",
receiverIdentifier: "policy receiver id", receiverCodeRequirement: "policy receiver code req")
var policy = TCCPolicy(
identifier: "policy id", codeRequirement: "policy code req",
receiverIdentifier: "policy receiver id", receiverCodeRequirement: "policy receiver code req")
policy.comment = "policy comment"
policy.identifierType = "policy id type"
policy.receiverIdentifierType = "policy receiver id type"
Expand All @@ -44,27 +45,31 @@ class TCCProfileBuilder: NSObject {
}

func buildTCCPolicies(allowed: Bool?, authorization: TCCPolicyAuthorizationValue?) -> [String: [TCCPolicy]] {
return ["SystemPolicyAllFiles": [buildTCCPolicy(allowed: allowed, authorization: authorization)],
"AppleEvents": [buildTCCPolicy(allowed: allowed, authorization: authorization)]]
return [
"SystemPolicyAllFiles": [buildTCCPolicy(allowed: allowed, authorization: authorization)],
"AppleEvents": [buildTCCPolicy(allowed: allowed, authorization: authorization)]
]
}

func buildTCCContent(_ contentIndex: Int, allowed: Bool?, authorization: TCCPolicyAuthorizationValue?) -> TCCProfile.Content {
return TCCProfile.Content(payloadDescription: "Content Desc \(contentIndex)",
displayName: "Content Name \(contentIndex)",
identifier: "Content ID \(contentIndex)",
organization: "Content Org \(contentIndex)",
type: "Content type \(contentIndex)",
uuid: "Content UUID \(contentIndex)",
version: contentIndex,
services: buildTCCPolicies(allowed: allowed, authorization: authorization))
return TCCProfile.Content(
payloadDescription: "Content Desc \(contentIndex)",
displayName: "Content Name \(contentIndex)",
identifier: "Content ID \(contentIndex)",
organization: "Content Org \(contentIndex)",
type: "Content type \(contentIndex)",
uuid: "Content UUID \(contentIndex)",
version: contentIndex,
services: buildTCCPolicies(allowed: allowed, authorization: authorization))
}

func buildProfile(allowed: Bool? = nil, authorization: TCCPolicyAuthorizationValue? = nil) -> TCCProfile {
var profile = TCCProfile(organization: "Test Org",
identifier: "Test ID",
displayName: "Test Name",
payloadDescription: "Test Desc",
services: [:])
var profile = TCCProfile(
organization: "Test Org",
identifier: "Test ID",
displayName: "Test Name",
payloadDescription: "Test Desc",
services: [:])
profile.content = [buildTCCContent(1, allowed: allowed, authorization: authorization)]
profile.version = 100
profile.uuid = "the uuid"
Expand Down
57 changes: 28 additions & 29 deletions PPPC UtilityTests/ModelTests/ModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ class ModelTests: XCTestCase {

func testGetExecutableBasedOnIdentifierAndCodeRequirement_BundleIdentifierType() {
// given
let identifier = "com.example.App"
let codeRequirement = "testCodeRequirement"
let identifier = "com.example.App"
let codeRequirement = "testCodeRequirement"

// when
let executable = model.getExecutableFrom(identifier: identifier, codeRequirement: codeRequirement)
let executable = model.getExecutableFrom(identifier: identifier, codeRequirement: codeRequirement)

// then
XCTAssertEqual(executable.displayName, "App")
XCTAssertEqual(executable.codeRequirement, codeRequirement)
XCTAssertEqual(executable.iconPath, IconFilePath.application)
XCTAssertEqual(executable.displayName, "App")
XCTAssertEqual(executable.codeRequirement, codeRequirement)
XCTAssertEqual(executable.iconPath, IconFilePath.application)
}

func testGetExecutableBasedOnIdentifierAndCodeRequirement_PathIdentifierType() {
Expand All @@ -71,16 +71,16 @@ class ModelTests: XCTestCase {

func testGetExecutableFromComputerBasedOnIdentifier() {
// given
let identifier = "com.apple.Safari"
let codeRequirement = "randomReq"
let identifier = "com.apple.Safari"
let codeRequirement = "randomReq"

// when
let executable = model.getExecutableFrom(identifier: identifier, codeRequirement: codeRequirement)
let executable = model.getExecutableFrom(identifier: identifier, codeRequirement: codeRequirement)

// then
XCTAssertEqual(executable.displayName, "Safari")
XCTAssertNotEqual(executable.iconPath, IconFilePath.application)
XCTAssertNotEqual(codeRequirement, executable.codeRequirement)
XCTAssertEqual(executable.displayName, "Safari")
XCTAssertNotEqual(executable.iconPath, IconFilePath.application)
XCTAssertNotEqual(codeRequirement, executable.codeRequirement)
}

func testGetExecutableFromSelectedExecutables() {
Expand Down Expand Up @@ -189,10 +189,8 @@ class ModelTests: XCTestCase {
// given
let exe1 = Executable(identifier: "one", codeRequirement: "oneReq")
let exe2 = Executable(identifier: "two", codeRequirement: "twoReq")

exe1.appleEvents = [AppleEventRule(source: exe1, destination: exe2, value: true)]
exe2.policy.SystemPolicyAllFiles = "Allow"

model.selectedExecutables = [exe1, exe2]
model.usingLegacyAllowKey = true

Expand All @@ -209,7 +207,6 @@ class ModelTests: XCTestCase {
XCTAssertNotNil(profile.uuid)
XCTAssertEqual(1, profile.version)

// then check policy settings
// then verify the payload content top level
XCTAssertEqual(1, profile.content.count)
profile.content.forEach { content in
Expand All @@ -218,9 +215,8 @@ class ModelTests: XCTestCase {

// then verify the services
XCTAssertEqual(2, content.services.count)
let appleEvents = content.services["AppleEvents"]
XCTAssertNotNil(appleEvents)
let appleEventsPolicy = appleEvents?.first
let appleEventsPolicy = content.services["AppleEvents"]?.first
XCTAssertNotNil(appleEventsPolicy)
XCTAssertEqual("one", appleEventsPolicy?.identifier)
XCTAssertEqual("oneReq", appleEventsPolicy?.codeRequirement)
XCTAssertEqual("bundleID", appleEventsPolicy?.identifierType)
Expand All @@ -230,9 +226,8 @@ class ModelTests: XCTestCase {
XCTAssertTrue(appleEventsPolicy?.allowed == true)
XCTAssertNil(appleEventsPolicy?.authorization)

let allFiles = content.services["SystemPolicyAllFiles"]
XCTAssertNotNil(allFiles)
let allFilesPolicy = allFiles?.first
let allFilesPolicy = content.services["SystemPolicyAllFiles"]?.first
XCTAssertNotNil(allFilesPolicy)
XCTAssertEqual("two", allFilesPolicy?.identifier)
XCTAssertEqual("twoReq", allFilesPolicy?.codeRequirement)
XCTAssertEqual("bundleID", allFilesPolicy?.identifierType)
Expand Down Expand Up @@ -481,14 +476,18 @@ class ModelTests: XCTestCase {
func testChangingFromAuthorizationKeyToLegacyAllowKeyWithMoreComplexVaues() {
// given
let allowStandard = TCCProfileDisplayValue.allowStandardUsersToApprove.rawValue
let p1Settings = ["SystemPolicyAllFiles": "Allow",
"ListenEvent": allowStandard,
"ScreenCapture": "Deny",
"Camera": "Deny"]

let p2Settings = ["SystemPolicyAllFiles": "Deny",
"ScreenCapture": allowStandard,
"Calendar": "Allow"]
let p1Settings = [
"SystemPolicyAllFiles": "Allow",
"ListenEvent": allowStandard,
"ScreenCapture": "Deny",
"Camera": "Deny"
]

let p2Settings = [
"SystemPolicyAllFiles": "Deny",
"ScreenCapture": allowStandard,
"Calendar": "Allow"
]
let builder = ModelBuilder().addExecutable(settings: p1Settings)
model = builder.addExecutable(settings: p2Settings).build()
model.usingLegacyAllowKey = false
Expand Down
5 changes: 4 additions & 1 deletion PPPC UtilityTests/ModelTests/PPPCServicesManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class PPPCServicesManagerTests: XCTestCase {
let actual = service.userHelp

// then
XCTAssertEqual(actual, "Use to deny specified apps access to the camera.\n\nMDM Key: Camera\nRelated entitlements: [\"com.apple.developer.avfoundation.multitasking-camera-access\", \"com.apple.security.device.camera\"]")
XCTAssertEqual(
actual,
"Use to deny specified apps access to the camera.\n\nMDM Key: Camera\nRelated entitlements: [\"com.apple.developer.avfoundation.multitasking-camera-access\", \"com.apple.security.device.camera\"]"
)
}

func testUserHelp_withoutEntitlements() throws {
Expand Down
3 changes: 2 additions & 1 deletion PPPC UtilityTests/ModelTests/SemanticVersionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
//

import Foundation
@testable import PPPC_Utility
import XCTest

@testable import PPPC_Utility

class SemanticVersionTests: XCTestCase {
func testLessThan() {
// given
Expand Down
22 changes: 11 additions & 11 deletions PPPC UtilityTests/NetworkingTests/JamfProAPIClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import XCTest
@testable import PPPC_Utility

class JamfProAPIClientTests: XCTestCase {
func testOAuthTokenRequest() throws {
// given
let authManager = NetworkAuthManager(username: "", password: "")
let apiClient = JamfProAPIClient(serverUrlString: "https://something", tokenManager: authManager)
func testOAuthTokenRequest() throws {
// given
let authManager = NetworkAuthManager(username: "", password: "")
let apiClient = JamfProAPIClient(serverUrlString: "https://something", tokenManager: authManager)

// when
let request = try apiClient.oauthTokenRequest(clientId: "mine&yours", clientSecret: "foo bar")
// when
let request = try apiClient.oauthTokenRequest(clientId: "mine&yours", clientSecret: "foo bar")

// then
let body = try XCTUnwrap(request.httpBody)
let bodyString = String(data: body, encoding: .utf8)
XCTAssertEqual(bodyString, "grant_type=client_credentials&client_id=mine%26yours&client_secret=foo%20bar")
}
// then
let body = try XCTUnwrap(request.httpBody)
let bodyString = String(data: body, encoding: .utf8)
XCTAssertEqual(bodyString, "grant_type=client_credentials&client_id=mine%26yours&client_secret=foo%20bar")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class MockNetworking: Networking {
throw error
}

let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
let expiration = try XCTUnwrap(formatter.date(from: "2950-06-22T22:05:58.81Z"))
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
let expiration = try XCTUnwrap(formatter.date(from: "2950-06-22T22:05:58.81Z"))

return Token(value: "xyz", expiresAt: expiration)
return Token(value: "xyz", expiresAt: expiration)
}
}

Expand Down
Loading
Loading