Change license to AGPL
This commit:
- Updates the `LICENSE` file
- Start every file with something like:
// Copyright YEAR_FIRST_PUBLISHED Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
---
First, I removed existing license headers with this Ruby 3.1.2 script:
require 'set'
EXTENSIONS_TO_CHECK = Set['.h', '.hpp', '.cpp', '.m', '.mm', '.pch', '.swift']
same = 0
different = 0
all_files = `git ls-files`.lines.map { |line| line.strip }
all_files.each do |relative_path|
if relative_path == 'Pods'
next
end
unless EXTENSIONS_TO_CHECK.include? File.extname(relative_path)
next
end
path = File.expand_path(relative_path)
contents = File.read(path)
new_contents = contents.sub(/\/\/\n\/\/ Copyright .*\n\/\/\n\n/, '')
if contents == new_contents
same += 1
else
different += 1
end
File.write(path, new_contents)
end
puts "updated #{different} file(s), left #{same} untouched"
I'm sure this script could be improved, but it worked well enough.
Then, I created `Scripts/lint/lint-license-headers` and ran it to auto-
fix a lot of files. This changed the mode of some files, but I think
that's actually desirable. For example,
`SignalServiceKit/src/Util/AppContext.m` previously had a mode of
`0755/-rwxr-xr-x`, and it's now `0644/-rw-r--r--`.
Then I fixed some stragglers and updated the precommit script.
See [a similar change in the Desktop app][0].
[0]: 8bfaf598af
115 lines
4.1 KiB
Swift
115 lines
4.1 KiB
Swift
//
|
|
// Copyright 2020 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
//
|
|
|
|
import Foundation
|
|
import XCTest
|
|
|
|
@testable import SignalServiceKit
|
|
|
|
// MARK: - RateLimiter testing
|
|
|
|
class ContactDiscoveryTaskTest: SSKBaseTestSwift {
|
|
var dut: ContactDiscoveryTask.RateLimiter! = nil
|
|
|
|
override func setUp() {
|
|
super.setUp()
|
|
dut = ContactDiscoveryTask.RateLimiter.createForTesting()
|
|
}
|
|
|
|
func testDefaultState() {
|
|
XCTAssertNil(dut.currentRetryAfterDate(forCriticalPriority: false))
|
|
XCTAssertNil(dut.currentRetryAfterDate(forCriticalPriority: true))
|
|
}
|
|
|
|
/// Standard retry after periods should not apply to critical attempts
|
|
func testSetStandardRetryAfter() {
|
|
// Setup
|
|
let retryAfter = Date(timeIntervalSinceNow: 5)
|
|
|
|
// Test
|
|
dut.updateRetryAfter(with: retryAfter, criticalPriority: false)
|
|
|
|
// Verify
|
|
XCTAssertEqual(retryAfter, dut.currentRetryAfterDate(forCriticalPriority: false))
|
|
XCTAssertNil(dut.currentRetryAfterDate(forCriticalPriority: true))
|
|
}
|
|
|
|
/// Critical retry after periods should apply to standard attempts
|
|
func testSetCriticalRetryAfter() {
|
|
// Setup
|
|
let retryAfter = Date(timeIntervalSinceNow: 5)
|
|
|
|
// Test
|
|
dut.updateRetryAfter(with: retryAfter, criticalPriority: true)
|
|
|
|
// Verify
|
|
XCTAssertEqual(retryAfter, dut.currentRetryAfterDate(forCriticalPriority: false))
|
|
XCTAssertEqual(retryAfter, dut.currentRetryAfterDate(forCriticalPriority: true))
|
|
}
|
|
|
|
/// Standard retry after periods may not apply to critical attempts. Expect the later, standard entry to only apply to standard attempts
|
|
func testSetDifferentDates_CriticalExpiresFirst() {
|
|
// Setup
|
|
let standardRetryAfter = Date(timeIntervalSinceNow: 5)
|
|
let criticalRetryAfter = Date(timeIntervalSinceNow: 3)
|
|
|
|
// Test
|
|
dut.updateRetryAfter(with: standardRetryAfter, criticalPriority: false)
|
|
dut.updateRetryAfter(with: criticalRetryAfter, criticalPriority: true)
|
|
|
|
// Verify
|
|
XCTAssertEqual(standardRetryAfter, dut.currentRetryAfterDate(forCriticalPriority: false))
|
|
XCTAssertEqual(criticalRetryAfter, dut.currentRetryAfterDate(forCriticalPriority: true))
|
|
}
|
|
|
|
/// Critical retry after periods always apply to standard. Expect the later, critical retry after to apply to both
|
|
func testSetDifferentDates_StandardExpiresFirst() {
|
|
// Setup
|
|
let standardRetryAfter = Date(timeIntervalSinceNow: 3)
|
|
let criticalRetryAfter = Date(timeIntervalSinceNow: 5)
|
|
|
|
// Test
|
|
dut.updateRetryAfter(with: standardRetryAfter, criticalPriority: false)
|
|
dut.updateRetryAfter(with: criticalRetryAfter, criticalPriority: true)
|
|
|
|
// Verify
|
|
XCTAssertEqual(criticalRetryAfter, dut.currentRetryAfterDate(forCriticalPriority: false))
|
|
XCTAssertEqual(criticalRetryAfter, dut.currentRetryAfterDate(forCriticalPriority: true))
|
|
}
|
|
|
|
/// RateLimiter should track the latest date that it's been informed of
|
|
func testDatePriority() {
|
|
// Setup
|
|
let input1 = Date(timeIntervalSinceNow: 3)
|
|
let input2 = Date(timeIntervalSinceNow: 1)
|
|
let input3 = Date(timeIntervalSinceNow: 5)
|
|
|
|
// Test
|
|
dut.updateRetryAfter(with: input1, criticalPriority: false)
|
|
let expiry1 = dut.currentRetryAfterDate(forCriticalPriority: false)
|
|
dut.updateRetryAfter(with: input2, criticalPriority: false)
|
|
let expiry2 = dut.currentRetryAfterDate(forCriticalPriority: false)
|
|
dut.updateRetryAfter(with: input3, criticalPriority: false)
|
|
let expiry3 = dut.currentRetryAfterDate(forCriticalPriority: false)
|
|
|
|
// Verify
|
|
XCTAssertEqual(expiry1, input1)
|
|
XCTAssertEqual(expiry2, input1)
|
|
XCTAssertEqual(expiry3, input3)
|
|
}
|
|
|
|
/// RateLimiter should return nil if the date is in the past
|
|
func testPastDates() {
|
|
// Setup
|
|
let pastDate = Date(timeIntervalSinceNow: -1)
|
|
|
|
// Test
|
|
dut.updateRetryAfter(with: pastDate, criticalPriority: false)
|
|
|
|
// Verify
|
|
XCTAssertNil(dut.currentRetryAfterDate(forCriticalPriority: false))
|
|
}
|
|
}
|