Skip to content

Commit

Permalink
♻️ Validate push app
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt authored and iujames committed Sep 17, 2024
1 parent 6611a28 commit ce53b57
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions Sources/AppcuesKit/Push/ParsedNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation

internal struct ParsedNotification {
let accountID: String
let applicationID: String
let userID: String
let notificationID: String
let workflowID: String?
Expand All @@ -23,12 +24,14 @@ internal struct ParsedNotification {

init?(userInfo: [AnyHashable: Any]) {
guard let accountID = userInfo["appcues_account_id"] as? String,
let userID = userInfo["appcues_user_id"] as? String,
let notificationID = userInfo["appcues_notification_id"] as? String else {
let applicationID = userInfo["appcues_app_id"] as? String,
let userID = userInfo["appcues_user_id"] as? String,
let notificationID = userInfo["appcues_notification_id"] as? String else {
return nil
}

self.accountID = accountID
self.applicationID = applicationID
self.userID = userID
self.notificationID = notificationID

Expand Down
4 changes: 3 additions & 1 deletion Sources/AppcuesKit/Push/PushMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ internal class PushMonitor: PushMonitoring {

config.logger.info("Push response received:\n%{private}@", userInfo.description)

guard let parsedNotification = ParsedNotification(userInfo: userInfo) else {
guard let parsedNotification = ParsedNotification(userInfo: userInfo),
parsedNotification.accountID == config.accountID,
parsedNotification.applicationID == config.applicationID else {
// Not an Appcues push
return false
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/AppcuesKitTests/Push/PushMonitorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class PushMonitorTests: XCTestCase {
var appcues: MockAppcues!

override func setUp() {
let config = Appcues.Config(accountID: "00000", applicationID: "abc")
let config = Appcues.Config(accountID: "00000", applicationID: "<app-id>")
appcues = MockAppcues(config: config)
pushMonitor = PushMonitor(container: appcues.container)
}
Expand Down Expand Up @@ -380,7 +380,8 @@ extension Dictionary where Key == AnyHashable, Value == Any {
"body": "Notification from appcues"
]
],
"appcues_account_id": "103523",
"appcues_account_id": "00000",
"appcues_app_id": "<app-id>",
"appcues_user_id": "default-00000",
"appcues_notification_id": "DEADBEEF-0000-0000-0000-000000000001",
"appcues_workflow_id": "DEADBEEF-0000-0000-0000-000000000002",
Expand Down

0 comments on commit ce53b57

Please sign in to comment.