1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import Foundation
import UIKit
import XCTest
@testable import OldFella
extension SecureSessionUploadFixture {
func resolveHandle(_ request: URLRequest) throws -> (Int, Data) {
XCTAssertEqual(request.url?.host, "public.api.bsky.app")
return (200, Data("{\"did\":\"did:plc:reader\"}".utf8))
}
func resolveDID(_ request: URLRequest) throws -> (Int, Data) {
return (
200,
Data(
("{\"id\":\"did:plc:reader\",\"service\":[{\"id\":\"#atproto_pds\","
+ "\"type\":\"AtprotoPersonalDataServer\","
+ "\"serviceEndpoint\":\"https://pds.example.test\"}]}")
.utf8)
)
}
func createSession(_ request: URLRequest) throws -> (Int, Data) {
XCTAssertEqual(request.url?.host, "pds.example.test")
XCTAssertEqual(request.httpMethod, "POST")
XCTAssertNil(request.value(forHTTPHeaderField: "Authorization"))
let bodyData = request.url.flatMap { StubURLProtocol.recordedBody(for: $0) }
let body = bodyData.flatMap { try? JSONSerialization.jsonObject(with: $0) as? [String: String] }
XCTAssertEqual(body?["identifier"], "reader.bsky.social")
XCTAssertEqual(body?["password"], "dedicated-app-password")
return (
200,
Data(
("{\"handle\":\"reader.bsky.social\",\"did\":\"did:plc:reader\","
+ "\"accessJwt\":\"\(token)\",\"refreshJwt\":\"refresh-token\"}")
.utf8)
)
}
func profile(_ request: URLRequest) throws -> (Int, Data) {
XCTAssertEqual(request.url?.host, "pds.example.test")
XCTAssertEqual(request.value(forHTTPHeaderField: "Authorization"), "Bearer \(token)")
XCTAssertEqual(request.value(forHTTPHeaderField: "atproto-proxy"), "did:web:api.bsky.app#bsky_appview")
return (
200,
Data(
("{\"did\":\"did:plc:reader\",\"handle\":\"reader.bsky.social\","
+ "\"displayName\":\"Reader\","
+ "\"viewer\":{\"following\":\"at://did:plc:reader/app.bsky.graph.follow/followee\"}}")
.utf8)
)
}
}