Commit Graph

129 Commits

Author SHA1 Message Date
Max Radermacher
cf8593bbe3
Add tests for 2-way contact merging logic 2023-03-23 14:00:52 -07:00
Max Radermacher
ebf6b8f5e7
Support PNIs in SignalServiceAddress 2023-03-23 12:43:01 -07:00
Evan Hahn
91c841dc3c Merge redundant callingCode(fromCountryCode:) tests
This test-only change should have no user impact.

`PhoneNumberUtil.callingCode(fromCountryCode:)` was tested in two
places. This combines them and moves the tests to Swift.
2023-03-15 12:41:19 -05:00
Harry
a146e18aaf
Set up account state and exit registration
* Go to chat list view after registration

* sync system contacts during registration

* Use explicit local credentials for storage service operations during registration

* fix tests

* Quick hack to get through double pin confirmation

* Finishing touches

* lint

* fix build

* reload phone number discoverability after storage service sync

* fix tests again

* Take chat auth on account and contact record initializers

* Change around branches for clarity in OWSUserProfile

* pr comments

* Split ChatServiceAuth into the same and AuthedAccount

* fix tests

* merge woes
2023-03-09 21:54:51 -08:00
Sasha Weiss
82fad84831
Initial implementation of PNI change-number 2023-03-09 17:13:16 -08:00
Max Radermacher
6dede44db6
Remove unused CDSv1 code
It’s been replaced by CDSv2.
2023-02-22 14:43:09 -08:00
Max Radermacher
42bfe615ff
Check PNI before E164 in CDS lookups 2023-02-22 10:37:39 -08:00
Max Radermacher
59593c3c97
Add ServiceId & E164 types
* Use the new E164 type in a few places
* Use the new ServiceId type in a few places
2023-02-21 23:13:46 -08:00
Evan Hahn
3586894501
Consolidate E164 -> PhoneNumber code 2023-02-16 09:57:15 -08:00
Max Radermacher
56154557dd
Add isStructurallyValidE164
This merges & replaces `resemblesE164:` and `isValidE164`.

Co-authored-by: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com>
2023-02-13 13:45:00 -08:00
Max Radermacher
73ac0c69a1
Add SignalRecipient.deviceIds 2023-02-08 13:46:15 -08:00
Harry
003cc19e62
Update SignalCoreKit. Use explicit DispatchQueue instead of relying on the implicit type on promise 'on' params
* Use explicit DispatchQueue instead of relying on the implicit type on promise 'on' params

* Update SignalCoreKit
2023-02-07 16:14:39 -08:00
Max Radermacher
3a1556ca46 Clean up & Swiftify allSortedContacts 2023-01-30 12:15:11 -08:00
Max Radermacher
d7c52b6ad0
Fix bugs marking SignalRecipients as registered
Previously, low-trust SignalRecipients wouldn’t be marked as registered
unless they were newly-created. Now, they are marked as registered in
places where they should be (eg, successfully sending a message or
fetching a pre key means that the device exists).

As part of this change, SignalRecipients are unregistered by default,
though most call sites still mark them as registered immediately, so the
behavior in practice will be identical. There are a few places (such as
ensureAccountId) which will no longer mark new values as registered.

Finally, creating a new SignalRecipient would also update Storage
Service, even if that recipient was created in response to a storage
service update. Now, recipients updated as part of storage service
operations won’t immediately trigger another storage service update.
2023-01-03 13:23:33 -08:00
Max Radermacher
921301cdb0
Add CDSv2 2022-12-14 16:30:35 -08:00
Evan Hahn
127958a8fa
Swiftify a few phone number utility methods
This converts `PhoneNumberUtil.countryNameFromCountryCode`,
`PhoneNumberUtil.countryCodesForSearchTerm`, and `PhoneNumberUtil.name`
to Swift. I renamed `PhoneNumberUtil.name` to `does` for clarity, and
made it private.

This also lets us remove several utility methods.
2022-12-07 08:32:24 -06:00
Max Radermacher
50e0405276
Add ContactDiscoveryManager
RATE LIMITS & IS CRITICAL PRIORITY

Before this change, there was a notion of “critical” discovery tasks
that had their own rate limit, and that rate limit was used for
UUIDBackfillTask. In this change, that logic has been generalized to
consider a separate rate limit for additional request types.

QUEUE PRIORITIES

All of the discovery operations were updated to use `.userInitiated` as
their priority. Before this change, the `UUIDBackfillTask` and message
sending flow used lower priorities. However, both of those should use
higher priorities -- the former blocks receiving messages and the latter
blocks outgoing messages. This change allows the code to be simplified.

TESTS

This removes most of the existing `UUIDBackfillTaskTest` test cases
(they were commented out) and all of the `ContactDiscoveryTaskTest` test
cases (which were for the rate limiter, which has been moved elsewhere).

It introduces a few new tests. These aren’t meant to be exhausive;
instead, they’re meant to hit most of the code in the new classes and a
few specific edge cases that aren’t likely to be hit in normal use.
2022-11-15 13:37:28 -08:00
Evan Hahn
b7cb7eb403
Test TSContactThread's canSendChatMessagesToThread() 2022-10-28 16:16:00 -05:00
Evan Hahn
370ff654e7
Change license to AGPL
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
2022-10-13 08:25:37 -05:00
Max Radermacher
3ffa2dca2c
Fix nullability for countryNameFromCountryCode 2022-10-11 17:30:58 -07:00
Evan Hahn
a066511a62 Remove useless test setup/teardown
We had a lot of functions like this, which are useless:

    override func setUp() {
        super.setUp()
    }

This removes them.
2022-10-04 14:06:34 -07:00
Evan Hahn
c5b4f67613 Swiftify contact thread tests
_This change should have no user impact._

A very mechanical change. No surprises.
2022-09-22 14:41:59 -07:00
Max Radermacher
88bc6e43d8 Refactor encodeE164s
- Remove duplicate check for a `+` at the beginning of each value.

- Don’t return a big-endian UInt64 from a method. The type information
  (unfortunately) doesn’t include endianness, which makes that approach
  somewhat more error-prone.

- Add a type that tracks validated input/output pairs. Future changes
  will want to perform the validation and then use both input & output.
2022-09-21 12:47:29 -07:00
Nora Trapp
9776699137 Sync when contacts become unregistered 2022-09-15 14:09:03 -07:00
Evan Hahn
95566b6952 Swiftify group thread test
A very mechanical change.
2022-09-14 02:18:33 +00:00
Evan Hahn
787a688b08 Rewrite PhoneNumber.tryParsePhoneNumber tests
This change should have no user impact.

This commit:

- Rewrites the tests in Swift
- Removes some redundant tests
- For North American phone numbers, uses `555-01XX` phone numbers
  (because "only 555-0100 through 555-0199 are now specifically reserved
  for fictional use; the other numbers have been reserved for actual
  assignment)
2022-08-31 00:36:06 +00:00
Evan Hahn
a6b395b11f Remove long-skipped phone number tests for Mexico
This change should have no user impact.

This removes a test that's been skipped since 2020 (see
5c976b0acd). I think this is okay given
that (1) we've skipped it for over 2 years (2) [we already have some
tests for Mexican phone numbers][0].

[0]: 895c1b7576/SignalServiceKit/tests/Contacts/PhoneNumberTest.swift (L10-L25)
2022-08-30 16:46:37 -07:00
Evan Hahn
4fc5d75793 Update libPhoneNumber-iOS
This updates our libPhoneNumber dependency. See [the libPhoneNumber-iOS
commit][0].

According to [the upstream libphonenumber release notes][1], they
updated the formatting for +49 numbers. That caused a test to break, so
I updated it (and tested a few additional dialing codes).

[0]: 8b6f552682
[1]: 90503ecef3/release_notes.txt (L21)
2022-08-28 15:31:06 +00:00
george-signal
87533d2b67
Improve phone number parsing.
* Improve phone number parsing.

Previously, if you entered a phone number
including a country code during registration you'd
have a duplicate country code. Signal on Android
did not have this bug because it uses a different
API inlibphonenumber. This diff changes iPhone to
use the same API, which is smart enough to remove
the country code from the phone number the user
entered if needed.

Co-authored-by: Evan Hahn <evanhahn@signal.org>
2022-08-23 11:56:06 -07:00
Max Radermacher
686f99f039 Fix ContactDiscoveryOperationTest
Make `encodeE164s` a static method since it doesn’t need to access any
details from the operation instance.

Also move the test to SignalServiceKitTests.
2022-08-22 09:11:42 -07:00
Sasha Weiss (Signal)
98151dfd0d
Don't need transactions to build group models 2022-07-12 10:23:12 -07:00
Nora Trapp
7bd167f815
Initial story sending support
* Little fix for context menu

* Add 'My Stories' section to stories tab

* Add new story thread types

* Show stories in conversation picker

* Support for sending stories

* Update story list when sending stories

* Add basic 'My Stories' view controller

* Initial stories settings screens

* Consolidate TSPrivateStoryThread and TSMyStoryThread into one class

* Require an explicit read transaction to initialize an outgoing message

* Fix linting

* Allow enabling group story from internal settings

* Fix tests

* PR Feedback
2022-06-10 22:28:03 -04:00
Evan Hahn
8f3eba01a3 Add message to all XCTFails
SwiftLint [gets upset][0] when `XCTFail` doesn't have a message. We had
two tests that lacked these, so I added them.

Part of my ongoing quest to get to "SwiftLint zero".

[0]: https://realm.github.io/SwiftLint/xctfail_message.html
2022-05-04 09:54:46 -05:00
Evan Hahn
04d7bb7462 Stop using arc4random in Swift files
This removes calls to `arc4random` and `arc4random_uniform` and replaces
them with calls to `Int.random` or equivalent.

These are a little less readable, which may be [why SwiftLint doesn't
like them][0]. (SwiftLint calls them "legacy", possibly because they're
not strong random number generators, but I couldn't find a clear
explanation for this anywhere, including [the original PR][1].)

This is the kind of change that's error-prone, so I wrote [a simple
script to help avoid regressions][2]. The script runs 10,000 iterations
of the old and new RNG and compares the ranges, reporting differences.
(Some differences are likely, like the ones that involve floats; others
are very unlikely to have differences.)

`git grep arc4random | grep swift` returns no results after this change.
Same for [everything else SwiftLint checks for][3].

[0]: https://realm.github.io/SwiftLint/legacy_random.html
[1]: https://github.com/realm/SwiftLint/pull/2419
[2]: https://gist.github.com/EvanHahn-Signal/9c75c9f484f4778149cbde3eafc9b285
[3]: ea6cc50890/Source/SwiftLintFramework/Rules/Idiomatic/LegacyRandomRule.swift (L23-L27)
2022-05-03 10:19:07 -05:00
Michelle Linington
84be44880e PR Feedback 2022-04-08 19:36:27 -07:00
Michelle Linington
a36671c4c2 Lint 2022-04-08 19:01:43 -07:00
Michelle Linington
78e00e310e Adds a bunch of tests 2022-04-08 19:01:43 -07:00
Evan Hahn
de105468a4 Assume everyone is GV2-capable 2022-03-22 17:11:57 -05:00
Dimitris Apostolou
62724cf0be Fix typos 2022-03-18 11:31:06 -07:00
Michelle Linington
e322921b10 Fix broken tests
If a test inserts a recipient, we need to have a registered local
address to perform some of our FTS index checks
2022-03-03 14:23:51 -08:00
George Nachman
d305bc66a3 Optimize searching for verification status, redux.
Commit 451fa08c22
had some bugs and was reverted by commit
12883e5db5.

This commit brings it back along with fixes.

Specific bug fixes:

* Verification status for a group was inverted.
* The local address should not be considered for
  deciding if a group is verified.
2022-03-01 14:15:11 -08:00
Matthew Chen
ff497ead1b Fix broken test. 2021-12-01 15:38:01 -03:00
Matthew Chen
23a98d724c Fix edge case in uuid<->phone number mapping changes. 2021-12-01 15:34:07 -03:00
Matthew Chen
2d8dc4036c Add PhoneNumberUtilTestSwift. 2021-10-22 19:06:48 -03:00
Matthew Chen
007a00a17b Add PhoneNumberUtil singleton. 2021-10-22 19:06:15 -03:00
Matthew Chen
a0efdc2e95 Respond to CR. 2021-10-21 09:21:33 -03:00
Matthew Chen
5d780d1589 Apply script to normalize includes and imports. 2021-10-21 09:21:10 -03:00
Matthew Chen
c1a8005a74 Never emit invalid e164 in storage service contact records; be robust to invalid e164 incoming protos. 2021-09-01 16:33:16 -03:00
Matthew Chen
fcdca12cf5 Deprecate REST, Part 1
* Port socket manager to Swift.
* Clean up HTTP request success/failure state & errors.
* Rework network manager.
* Rework HTTP errors.
* Rework errors "properties": isRetryable, etc.
* Fix test breakage.
2021-08-18 14:25:36 -03:00
Matthew Chen
718120f725 Fix test imports. 2021-06-07 11:41:43 -04:00