Skip to content

Commit

Permalink
Fixes an issue that caused Case Insensitive filters to not work in sp…
Browse files Browse the repository at this point in the history
…ecial situations
  • Loading branch information
afterxleep committed Sep 10, 2024
1 parent 7d3ae5c commit b237aaa
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 37 deletions.
8 changes: 4 additions & 4 deletions Bouncer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@
buildSettings = {
CODE_SIGN_ENTITLEMENTS = SMSFilter/SMSFilter.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1038;
CURRENT_PROJECT_VERSION = 1077;
DEVELOPMENT_TEAM = J9F8F3PWTV;
INFOPLIST_FILE = SMSFilter/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -718,7 +718,7 @@
CODE_SIGN_ENTITLEMENTS = SMSFilter/SMSFilter.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1038;
CURRENT_PROJECT_VERSION = 1077;
DEVELOPMENT_TEAM = J9F8F3PWTV;
INFOPLIST_FILE = SMSFilter/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -868,7 +868,7 @@
CODE_SIGN_ENTITLEMENTS = Bouncer/Bouncer.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1038;
CURRENT_PROJECT_VERSION = 1077;
DEVELOPMENT_ASSET_PATHS = "\"Bouncer/Preview Content\"";
DEVELOPMENT_TEAM = J9F8F3PWTV;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -903,7 +903,7 @@
CODE_SIGN_ENTITLEMENTS = Bouncer/Bouncer.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1038;
CURRENT_PROJECT_VERSION = 1077;
DEVELOPMENT_ASSET_PATHS = "\"Bouncer/Preview Content\"";
DEVELOPMENT_TEAM = J9F8F3PWTV;
ENABLE_PREVIEWS = YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "578DCDA4-D7BB-4BAF-9711-B082B55E7BC1"
uuid = "181E32EE-2022-40AA-9162-6FA8824683F9"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SMSFilter/MessageFilterExtension.swift"
filePath = "Bouncer/Views/Tutorial/TutorialView.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "35"
endingLineNumber = "35"
landmarkName = "runFilters(_:context:completion:)"
landmarkType = "7">
startingLineNumber = "14"
endingLineNumber = "14"
landmarkName = "TutorialView"
landmarkType = "14">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
Expand Down
2 changes: 1 addition & 1 deletion Bouncer/Models/SMSFilter/SMSOfflineFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct SMSOfflineFilter {
let result = text.range(of: filter.phrase, options: matchOptions) != nil
os_log("FILTEREXTENSION - -- Match: %@", log: OSLog.messageFilterLog, type: .info, "\(result)")
os_log("FILTEREXTENSION - -- Method: Text", log: OSLog.messageFilterLog, type: .info)
return text.range(of: filter.phrase, options: .caseInsensitive) != nil
return result
}

private func matchRegex(text: String, filter: Filter) -> Bool {
Expand Down
Binary file modified BouncerTests/Models/AppSettingsDefaultsTests.swift.plist
Binary file not shown.
69 changes: 43 additions & 26 deletions BouncerTests/Models/SMSOfflineFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ import IdentityLookup

class SMSOfflineFilterTest: XCTestCase {

var messages = [
SMSMessage(sender: "ETB Comunicaciones", text: "ETB compra 100 megas y recibe 200 por 6 meses. Incluye extensor de velocidAd mas promocion especial. Llama ya sin costo al 018000413807. Ver TyC. Hasta 31 ago 2020"),
SMSMessage(sender: "+16205261342", text: "ULANKA: Get 50% in shoes starting today!")
]

override func setUp() {
super.setUp()
}
Expand All @@ -22,74 +17,92 @@ class SMSOfflineFilterTest: XCTestCase {
var smsFilter: SMSOfflineFilter
var filterResult: SMSOfflineFilterResponse

let message = SMSMessage(sender: "ETB Comunicaciones", text: "ETB compra 100 megas y recibe 200 por 6 meses. Incluye extensor de velocidAd mas promocion especial. Llama ya sin costo al 018000413807. Ver TyC. Hasta 31 ago 2020")

// Old style filters (Text + Regex)
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "etb", type: .any, action: .junk)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .junk)

smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "comunica", type: .sender, action: .transaction)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .transaction)

smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "mega", type: .message, action: .promotion)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .promotion)

smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "[a-z]cidad", type: .message, action: .junk, useRegex: true)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .junk)

// Content filter test
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "velocidad", type: .message, action: .junk, useRegex: false)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .junk)

// Content filter test
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "VeLoCiDad", type: .message, action: .junk, useRegex: false, caseSensitive: true)])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .none)

}


func testRegexFilter() {
var smsFilter: SMSOfflineFilter
var filterResult: SMSOfflineFilterResponse

let message = SMSMessage(sender: "ETB Comunicaciones", text: "ETB compra 100 megas y recibe 200 por 6 meses. Incluye extensor de velocidAd mas promocion especial. Llama ya sin costo al 018000413807. Ver TyC. Hasta 31 ago 2020")

// Regex filter test
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "[E].*[l][o]cidad", type: .message, action: .junk, useRegex: true)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .junk)

// Regex filter test (Case sensitive)
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "[E].*[l][o]CidAd", type: .message, action: .junk, useRegex: true, caseSensitive: true)])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .none)

// Regex filter test (Case sensitive)
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "[E].*[l][o]cidAd", type: .message, action: .junk, useRegex: true, caseSensitive: true)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .junk)

// Regex filter test (Case sensitive)
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "compra|algo|nuevo", type: .message, action: .junk, useRegex: true, caseSensitive: true)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .junk)

smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "compra|extensor|nuevo", type: .message, action: .junk, useRegex: true, caseSensitive: true)])
filterResult = smsFilter.filterMessage(message: messages[0])
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "compra|extensor|nuevo", type: .message, action: .junk, useRegex: true)])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .junk)

smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "(?=.*especial)(?=.*meses)(?=.*megas).*", type: .message, action: .junk, useRegex: true, caseSensitive: true)])
filterResult = smsFilter.filterMessage(message: messages[0])
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "(?=.*especial)(?=.*meses)(?=.*megas).*", type: .message, action: .junk, useRegex: true)])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .junk)

smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "(?=.*compra)(?=.*casa)(?=.*megas).*", type: .message, action: .junk, useRegex: true, caseSensitive: false)])
filterResult = smsFilter.filterMessage(message: messages[0])
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(), phrase: "(?=.*compra)(?=.*casa)(?=.*megas).*", type: .message, action: .junk, useRegex: true)])
filterResult = smsFilter.filterMessage(message: message)
print(filterResult.action)
XCTAssertEqual(filterResult.action, .none)

}

func testSubactionFilters() {
var smsFilter: SMSOfflineFilter
var filterResult: SMSOfflineFilterResponse

var message = SMSMessage(sender: "ETB Comunicaciones", text: "ETB compra 100 megas y recibe 200 por 6 meses. Incluye extensor de velocidAd mas promocion especial. Llama ya sin costo al 018000413807. Ver TyC. Hasta 31 ago 2020")

// SubAction filter tests
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(),
phrase: "etb",
type: .any,
action: .transaction,
subAction: .transactionOrder)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .transaction)
XCTAssertEqual(filterResult.subaction, .transactionalOrders)

Expand All @@ -98,7 +111,7 @@ class SMSOfflineFilterTest: XCTestCase {
type: .any,
action: .transaction,
subAction: .transactionFinance)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .transaction)
XCTAssertEqual(filterResult.subaction, .transactionalFinance)

Expand All @@ -107,7 +120,7 @@ class SMSOfflineFilterTest: XCTestCase {
type: .any,
action: .transaction,
subAction: .transactionReminders)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .transaction)
XCTAssertEqual(filterResult.subaction, .transactionalReminders)

Expand All @@ -116,7 +129,7 @@ class SMSOfflineFilterTest: XCTestCase {
type: .any,
action: .promotion,
subAction: .promotionOffers)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .promotion)
XCTAssertEqual(filterResult.subaction, .promotionalOffers)

Expand All @@ -125,16 +138,18 @@ class SMSOfflineFilterTest: XCTestCase {
type: .any,
action: .promotion,
subAction: .promotionCoupons)])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .promotion)
XCTAssertEqual(filterResult.subaction, .promotionalCoupons)

message = SMSMessage(sender: "+16205261342", text: "ULANKA: Get 50% in shoes starting today!")

smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(),
phrase: "ULANKA",
type: .any,
action: .promotion,
subAction: .promotionOffers)])
filterResult = smsFilter.filterMessage(message: messages[1])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .promotion)
XCTAssertEqual(filterResult.subaction, .promotionalOffers)
}
Expand All @@ -143,6 +158,8 @@ class SMSOfflineFilterTest: XCTestCase {
var smsFilter: SMSOfflineFilter
var filterResult: SMSOfflineFilterResponse

let message = SMSMessage(sender: "ETB Comunicaciones", text: "ETB compra 100 megas y recibe 200 por 6 meses. Incluye extensor de velocidAd mas promocion especial. Llama ya sin costo al 018000413807. Ver TyC. Hasta 31 ago 2020")

// Allow list filter tests
smsFilter = SMSOfflineFilter(filterList: [Filter(id: UUID(),
phrase: "etb",
Expand All @@ -155,7 +172,7 @@ class SMSOfflineFilterTest: XCTestCase {
action: .junk,
subAction: .none)
])
filterResult = smsFilter.filterMessage(message: messages[0])
filterResult = smsFilter.filterMessage(message: message)
XCTAssertEqual(filterResult.action, .allow)
XCTAssertEqual(filterResult.subaction, .none)
}
Expand Down

0 comments on commit b237aaa

Please sign in to comment.