OXYGENHUB
# b0e64e81e4fb oxygen / crates / oxy-server / tests / http.rs
22.3 KiB · Rust · last changed Roadmap across oxygen, oxygen-vscode, oxygenhub, oxygenhub-vscode and the runner 1 month ago source blame history raw
1
//! End-to-end: a real server on a loopback port, clients over HTTP.
2
3
use oxy_core::repo::{Repo, SignatureStatus};
4
use std::fs;
5
use std::net::TcpListener;
6
use std::path::Path;
7
8
fn write(root: &Path, rel: &str, content: &[u8]) {
9
    let p = root.join(rel);
10
    fs::create_dir_all(p.parent().unwrap()).unwrap();
11
    fs::write(p, content).unwrap();
12
}
13
14
/// Point `$OXY_HOME` at a throwaway directory once per test process so no
15
/// test reads or writes the developer's real user configuration or keys.
16
fn hermetic() {
17
    static ONCE: std::sync::Once = std::sync::Once::new();
18
    static DIR: std::sync::OnceLock<tempfile::TempDir> = std::sync::OnceLock::new();
19
    ONCE.call_once(|| {
20
        let d = tempfile::tempdir().unwrap();
21
        std::env::set_var("OXY_HOME", d.path());
22
        DIR.set(d).ok();
23
    });
24
}
25
26
fn start(root: &Path, tokens: Vec<String>) -> String {
27
    start_with(root, tokens, None)
28
}
29
30
fn start_with(root: &Path, tokens: Vec<String>, tls: Option<oxy_server::TlsFiles>) -> String {
31
    let listener = TcpListener::bind("127.0.0.1:0").unwrap();
32
    let port = listener.local_addr().unwrap().port();
33
    let scheme = if tls.is_some() { "https" } else { "http" };
34
    let cfg = oxy_server::ServerConfig {
35
        root: root.to_path_buf(),
36
        tokens,
37
        tls,
38
    };
39
    std::thread::spawn(move || oxy_server::run_blocking(listener, cfg).unwrap());
40
    // Give the acceptor a moment; the first request otherwise races the bind.
41
    std::thread::sleep(std::time::Duration::from_millis(50));
42
    format!("{scheme}://127.0.0.1:{port}")
43
}
44
45
/// A self-signed certificate for 127.0.0.1 written to `dir`: (cert, key).
46
fn self_signed(dir: &Path) -> (std::path::PathBuf, std::path::PathBuf) {
47
    fs::create_dir_all(dir).unwrap();
48
    let ck =
49
        rcgen::generate_simple_self_signed(vec!["127.0.0.1".into(), "localhost".into()]).unwrap();
50
    let cert = dir.join("cert.pem");
51
    let key = dir.join("key.pem");
52
    fs::write(&cert, ck.cert.pem()).unwrap();
53
    fs::write(&key, ck.signing_key.serialize_pem()).unwrap();
54
    (cert, key)
55
}
56
57
#[test]
58
fn clone_push_pull_over_http() {
59
    hermetic();
60
    let dir = tempfile::tempdir().unwrap();
61
    let root = dir.path();
62
    let served = root.join("served");
63
    Repo::init(&served.join("origin")).unwrap();
64
    let base = start(&served, vec![]);
65
    let url = format!("{base}/origin");
66
67
    let mut a = Repo::clone(&url, &root.join("a"))
68
        .unwrap()
69
        .with_home(root.join("home"));
70
    let (key, _) = a
71
        .create_identity(
72
            "Ada",
73
            "[email protected]",
74
            oxy_core::repo::IdentityScope::Repo,
75
        )
76
        .unwrap();
77
    write(&root.join("a"), "f.txt", b"hello\n");
78
    let h1 = a.commit("hello", &[]).unwrap();
79
    let r = a.push("origin", false).unwrap();
80
    assert!(r[0].ok, "{}", r[0].reason);
81
82
    let origin = Repo::open(&served.join("origin")).unwrap();
83
    assert_eq!(origin.bookmark_heads().unwrap(), vec![h1]);
84
    assert!(
85
        matches!(origin.authenticate_change(&h1).unwrap(), SignatureStatus::Valid { key: k, sealed: true, .. } if k == key)
86
    );
87
88
    let b = Repo::clone(&url, &root.join("b")).unwrap();
89
    assert_eq!(fs::read(root.join("b/f.txt")).unwrap(), b"hello\n");
90
    write(&root.join("b"), "g.txt", b"g\n");
91
    let h2 = b.commit("g", &[]).unwrap();
92
    assert!(b.push("origin", false).unwrap()[0].ok);
93
94
    let pr = a.pull("origin").unwrap();
95
    assert!(pr.changed && pr.checked_out);
96
    assert_eq!(fs::read(root.join("a/g.txt")).unwrap(), b"g\n");
97
    let mut heads = a.bookmark_heads().unwrap();
98
    heads.sort();
99
    let mut want = vec![h1, h2];
100
    want.sort();
101
    assert_eq!(heads, want);
102
103
    // Unknown repositories and names the server refuses are surfaced as errors.
104
    let err = Repo::clone(&format!("{base}/nope"), &root.join("c"))
105
        .err()
106
        .unwrap()
107
        .to_string();
108
    assert!(err.contains("404"), "{err}");
109
    fs::create_dir_all(served.join(".hidden/.oxy")).unwrap();
110
    assert!(Repo::clone(&format!("{base}/.hidden"), &root.join("d"))
111
        .err()
112
        .unwrap()
113
        .to_string()
114
        .contains("404"));
115
}
116
117
#[test]
118
fn objects_endpoint_serves_lazy_blobs() {
119
    hermetic();
120
    let dir = tempfile::tempdir().unwrap();
121
    let root = dir.path();
122
    let served = root.join("served");
123
    let origin = Repo::init(&served.join("origin")).unwrap();
124
    let big: Vec<u8> = (0..300_000u32).map(|i| (i % 253) as u8).collect(); // has NUL bytes: opaque
125
    write(&served.join("origin"), "big.bin", &big);
126
    write(&served.join("origin"), "t.txt", b"t\n");
127
    origin.commit("big", &[]).unwrap();
128
    let base = start(&served, vec![]);
129
    let url = format!("{base}/origin");
130
    let a = Repo::clone_with(&url, &root.join("a"), Some(1000), &[]).unwrap();
131
    assert_eq!(
132
        fs::read(root.join("a/big.bin")).unwrap(),
133
        big,
134
        "fetched through the objects endpoint during checkout"
135
    );
136
    assert!(!a.snapshot("status").unwrap().changed);
137
}
138
139
#[test]
140
fn push_requires_a_token_when_configured() {
141
    hermetic();
142
    let dir = tempfile::tempdir().unwrap();
143
    let root = dir.path();
144
    let served = root.join("served");
145
    Repo::init(&served.join("origin")).unwrap();
146
    let base = start(&served, vec!["s3cret".into()]);
147
    let url = format!("{base}/origin");
148
149
    // Reads are open.
150
    let mut a = Repo::clone(&url, &root.join("a")).unwrap();
151
    write(&root.join("a"), "f.txt", b"x\n");
152
    a.commit("x", &[]).unwrap();
153
    let err = a.push("origin", false).err().unwrap().to_string();
154
    assert!(err.contains("401"), "{err}");
155
156
    a.config.set("remote.origin.token", "wrong").unwrap();
157
    a.save_config().unwrap();
158
    assert!(a
159
        .push("origin", false)
160
        .err()
161
        .unwrap()
162
        .to_string()
163
        .contains("401"));
164
165
    a.config.set("remote.origin.token", "s3cret").unwrap();
166
    a.save_config().unwrap();
167
    assert!(a.push("origin", false).unwrap()[0].ok);
168
    let origin = Repo::open(&served.join("origin")).unwrap();
169
    assert_eq!(origin.bookmark_heads().unwrap().len(), 1);
170
}
171
172
#[test]
173
fn https_with_a_self_signed_certificate() {
174
    hermetic();
175
    let dir = tempfile::tempdir().unwrap();
176
    let root = dir.path();
177
    let served = root.join("served");
178
    Repo::init(&served.join("origin")).unwrap();
179
    let (cert, key) = self_signed(root);
180
    let base = start_with(
181
        &served,
182
        vec![],
183
        Some(oxy_server::TlsFiles {
184
            cert: cert.clone(),
185
            key,
186
        }),
187
    );
188
    let url = format!("{base}/origin");
189
190
    // Without trusting the certificate the clone fails; with `OXY_CA` it works.
191
    let err = Repo::clone(&url, &root.join("untrusted"))
192
        .err()
193
        .unwrap()
194
        .to_string();
195
    assert!(
196
        err.contains("certificate")
197
            || err.contains("tls")
198
            || err.contains("TLS")
199
            || err.contains("handshake"),
200
        "{err}"
201
    );
202
    std::env::set_var("OXY_CA", &cert);
203
    let mut a = Repo::clone(&url, &root.join("a")).unwrap();
204
    std::env::remove_var("OXY_CA");
205
    // Persist the trust for this remote so later commands need no env var.
206
    a.config
207
        .set("remote.origin.ca", cert.to_str().unwrap())
208
        .unwrap();
209
    a.save_config().unwrap();
210
    write(&root.join("a"), "f.txt", b"tls\n");
211
    let h = a.commit("over tls", &[]).unwrap();
212
    assert!(a.push("origin", false).unwrap()[0].ok);
213
    let origin = Repo::open(&served.join("origin")).unwrap();
214
    assert_eq!(origin.bookmark_heads().unwrap(), vec![h]);
215
    // A wrong CA is refused.
216
    let (other_cert, _) = self_signed(&root.join("other"));
217
    a.config
218
        .set("remote.origin.ca", other_cert.to_str().unwrap())
219
        .unwrap();
220
    a.save_config().unwrap();
221
    assert!(a.fetch("origin").is_err());
222
}
223
224
/// Eight clones push independent changes at the same moment. The server
225
/// serialises pushes per repository, so every push either lands or is
226
/// refused because the bookmark moved, and a pull-then-push retry lands it.
227
#[test]
228
fn concurrent_pushes_are_serialised() {
229
    hermetic();
230
    let dir = tempfile::tempdir().unwrap();
231
    let root = dir.path();
232
    let served = root.join("served");
233
    Repo::init(&served.join("origin")).unwrap();
234
    let base = start(&served, vec![]);
235
    let url = format!("{base}/origin");
236
    const N: usize = 8;
237
    let mut clones = Vec::new();
238
    for i in 0..N {
239
        let path = root.join(format!("c{i}"));
240
        Repo::clone(&url, &path).unwrap();
241
        clones.push(path);
242
    }
243
    let barrier = std::sync::Arc::new(std::sync::Barrier::new(N));
244
    let mut handles = Vec::new();
245
    for (i, path) in clones.into_iter().enumerate() {
246
        let barrier = barrier.clone();
247
        handles.push(std::thread::spawn(move || {
248
            let repo = Repo::open(&path).unwrap();
249
            write(
250
                &path,
251
                &format!("file-{i}.txt"),
252
                format!("from clone {i}\n").as_bytes(),
253
            );
254
            let h = repo.commit(&format!("change {i}"), &[]).unwrap();
255
            barrier.wait();
256
            // A push is refused either up front (the remote moved since the
257
            // clone's last fetch) or by the server's compare-and-swap; both
258
            // are answered by pulling and pushing again.
259
            for attempt in 0..(N * 4) {
260
                match repo.push("origin", false) {
261
                    Ok(r) if r.iter().all(|x| x.ok) => return (h, attempt),
262
                    Ok(_) => {}
263
                    Err(e)
264
                        if e.to_string().contains("pull first")
265
                            || e.to_string().contains("moved") => {}
266
                    Err(e) => panic!("clone {i}: {e}"),
267
                }
268
                repo.pull("origin")
269
                    .unwrap_or_else(|e| panic!("clone {i} pull: {e}"));
270
            }
271
            panic!("clone {i} never managed to push");
272
        }));
273
    }
274
    let mut hashes = Vec::new();
275
    let mut total_rejected = 0;
276
    for h in handles {
277
        let (hash, attempts) = h.join().unwrap();
278
        hashes.push(hash);
279
        total_rejected += attempts;
280
    }
281
    let origin = Repo::open(&served.join("origin")).unwrap();
282
    let mut heads = origin.bookmark_heads().unwrap();
283
    heads.sort();
284
    hashes.sort();
285
    assert_eq!(heads, hashes, "every independent change is a head");
286
    let snap = origin.load_state(&heads).unwrap().materialize();
287
    for i in 0..N {
288
        assert!(snap.files.contains_key(&format!("file-{i}.txt")));
289
    }
290
    assert!(!snap.is_conflicted());
291
    eprintln!("{total_rejected} pushes were refused for a moved bookmark and retried");
292
    // The operation log is a single chain: each accepted push builds on the last.
293
    let ops = origin.op_log().unwrap();
294
    assert!(ops.len() > N);
295
}
296
297
#[test]
298
fn a_bare_repository_is_served_and_browsed_without_a_working_copy() {
299
    hermetic();
300
    let dir = tempfile::tempdir().unwrap();
301
    let root = dir.path();
302
    let served = root.join("served");
303
    let hosted = Repo::init_bare(&served.join("lib")).unwrap();
304
    assert!(hosted.is_bare());
305
    assert!(
306
        hosted.working_copy().is_err(),
307
        "a bare repository has no working copy"
308
    );
309
    assert!(!served.join("lib").join(".oxy").join("workspace").exists());
310
    let base = start(&served, vec![]);
311
    let url = format!("{base}/lib");
312
313
    // A client clones the empty repository, commits twice, and pushes.
314
    let work = root.join("work");
315
    let client = Repo::clone(&url, &work).unwrap();
316
    write(&work, "src/lib.rs", b"pub fn one() {}\n");
317
    client.snapshot("test").unwrap();
318
    let c1 = client.commit("one", &[]).unwrap();
319
    write(&work, "src/lib.rs", b"pub fn one() {}\npub fn two() {}\n");
320
    client.snapshot("test").unwrap();
321
    let c2 = client.commit("two", &[]).unwrap();
322
    let results = client.push("origin", false).unwrap();
323
    assert!(results.iter().all(|r| r.ok), "{results:?}");
324
325
    // The host reads history, files and blame from the bookmark's state alone.
326
    let hosted = Repo::open(&served.join("lib")).unwrap();
327
    assert!(hosted.is_bare());
328
    let heads = hosted.bookmark_heads().unwrap();
329
    assert_eq!(heads, vec![c2]);
330
    let log = hosted.log().unwrap();
331
    assert_eq!(log.iter().map(|e| e.hash).collect::<Vec<_>>(), vec![c2, c1]);
332
    assert!(log.iter().all(|e| !e.is_working_copy));
333
    assert_eq!(hosted.log_state(&[c1]).unwrap().len(), 1);
334
    assert_eq!(
335
        hosted.file_at("src/lib.rs", Some(&heads)).unwrap(),
336
        b"pub fn one() {}\npub fn two() {}\n"
337
    );
338
    let blame = hosted.blame_in("src/lib.rs", &heads).unwrap();
339
    assert_eq!(
340
        blame.iter().map(|l| l.hash).collect::<Vec<_>>(),
341
        vec![c1, c2]
342
    );
343
    assert_eq!(hosted.log_for_path("src/lib.rs").unwrap().len(), 2);
344
    assert_eq!(hosted.diff_files(Some(&c2)).unwrap().len(), 1);
345
    assert!(matches!(
346
        hosted.verify_change(&c2).unwrap(),
347
        SignatureStatus::Unsigned | SignatureStatus::Valid { .. }
348
    ));
349
350
    // Snapshotting a bare repository is refused rather than inventing a working copy.
351
    assert!(hosted.snapshot("test").is_err());
352
}
353
354
/// A host embeds the protocol with its own backend: names with an owner
355
/// segment, reads gated per repository, and a push hook.
356
#[test]
357
fn a_custom_backend_embeds_the_protocol() {
358
    use axum::extract::{Path as AxPath, State};
359
    use axum::http::{HeaderMap, Method, StatusCode};
360
    use axum::response::{IntoResponse, Response};
361
    use oxy_server::{Access, Backend, Endpoint, Failure, Server};
362
    use std::sync::{Arc, Mutex};
363
364
    struct Hub {
365
        root: std::path::PathBuf,
366
        pushes: Arc<Mutex<Vec<String>>>,
367
    }
368
    impl Backend for Hub {
369
        fn open(&self, name: &str) -> Result<Repo, Failure> {
370
            let Some((owner, repo)) = name.split_once('/') else {
371
                return Err(Failure(StatusCode::NOT_FOUND, "no such repository".into()));
372
            };
373
            let dir = self.root.join(owner).join(repo);
374
            if !dir.join(".oxy").is_dir() {
375
                return Err(Failure(StatusCode::NOT_FOUND, "no such repository".into()));
376
            }
377
            Repo::open(&dir).map_err(|e| Failure(StatusCode::INTERNAL_SERVER_ERROR, e.to_string()))
378
        }
379
        fn authorize(
380
            &self,
381
            name: &str,
382
            access: Access,
383
            headers: &HeaderMap,
384
        ) -> Result<(), Failure> {
385
            // `secret/*` is private: unknown to anyone without the token, even for reads.
386
            let token = oxy_server::bearer_token(headers);
387
            if name.starts_with("secret/") && token != Some("s3cret") {
388
                return Err(Failure(StatusCode::NOT_FOUND, "no such repository".into()));
389
            }
390
            if access == Access::Push && token.is_none() {
391
                return Err(Failure(StatusCode::UNAUTHORIZED, "sign in to push".into()));
392
            }
393
            Ok(())
394
        }
395
        fn after_push(&self, name: &str, results: &[oxy_core::protocol::RefResult]) {
396
            self.pushes.lock().unwrap().push(format!(
397
                "{name}: {}",
398
                results.iter().filter(|r| r.ok).count()
399
            ));
400
        }
401
    }
402
    async fn route(
403
        State(server): State<Arc<Server>>,
404
        AxPath((owner, repo, endpoint)): AxPath<(String, String, String)>,
405
        method: Method,
406
        headers: HeaderMap,
407
        body: axum::body::Bytes,
408
    ) -> Response {
409
        match Endpoint::parse(&endpoint) {
410
            Some(e) => {
411
                server
412
                    .handle(format!("{owner}/{repo}"), e, &method, &headers, body)
413
                    .await
414
            }
415
            None => Failure(StatusCode::NOT_FOUND, "no such endpoint".into()).into_response(),
416
        }
417
    }
418
419
    hermetic();
420
    let dir = tempfile::tempdir().unwrap();
421
    let root = dir.path();
422
    Repo::init_bare(&root.join("repos/andy/app")).unwrap();
423
    Repo::init_bare(&root.join("repos/secret/plans")).unwrap();
424
    let pushes = Arc::new(Mutex::new(Vec::new()));
425
    let server = Server::new(Hub {
426
        root: root.join("repos"),
427
        pushes: pushes.clone(),
428
    });
429
    let listener = TcpListener::bind("127.0.0.1:0").unwrap();
430
    let port = listener.local_addr().unwrap().port();
431
    std::thread::spawn(move || {
432
        let rt = tokio::runtime::Builder::new_multi_thread()
433
            .enable_all()
434
            .build()
435
            .unwrap();
436
        rt.block_on(async move {
437
            listener.set_nonblocking(true).unwrap();
438
            let app = axum::Router::new()
439
                .route(
440
                    "/{owner}/{repo}/oxy/v1/{endpoint}",
441
                    axum::routing::any(route),
442
                )
443
                .with_state(server);
444
            axum::serve(tokio::net::TcpListener::from_std(listener).unwrap(), app)
445
                .await
446
                .unwrap();
447
        });
448
    });
449
    std::thread::sleep(std::time::Duration::from_millis(50));
450
    let base = format!("http://127.0.0.1:{port}");
451
452
    // Anonymous clone of the public repository works; the private one does not exist for outsiders.
453
    let work = root.join("work");
454
    let client = Repo::clone(&format!("{base}/andy/app"), &work).unwrap();
455
    assert!(Repo::clone(&format!("{base}/secret/plans"), &root.join("nope")).is_err());
456
457
    // A push needs a token; with one it lands and the hook sees it.
458
    write(&work, "a.txt", b"a\n");
459
    client.snapshot("test").unwrap();
460
    client.commit("a", &[]).unwrap();
461
    assert!(
462
        client.push("origin", false).is_err(),
463
        "anonymous push must be refused"
464
    );
465
    let mut client = client;
466
    client.config.set("remote.origin.token", "s3cret").unwrap();
467
    let results = client.push("origin", false).unwrap();
468
    assert!(results.iter().all(|r| r.ok), "{results:?}");
469
    assert_eq!(pushes.lock().unwrap().as_slice(), ["andy/app: 1"]);
470
471
    let hosted = Repo::open(&root.join("repos/andy/app")).unwrap();
472
    assert_eq!(hosted.bookmark_heads().unwrap().len(), 1);
473
}
474
475
/// A hosted repository created unbound adopts the id of the first
476
/// repository pushed to it; before that it cannot be cloned or fetched.
477
#[test]
478
fn an_unbound_repository_adopts_the_first_pushers_id() {
479
    hermetic();
480
    let dir = tempfile::tempdir().unwrap();
481
    let root = dir.path();
482
    let served = root.join("served");
483
    let hosted = Repo::init_bare_unbound(&served.join("lib")).unwrap();
484
    assert!(hosted.is_unbound());
485
    assert_eq!(hosted.id().unwrap(), [0; 16]);
486
    let base = start(&served, vec![]);
487
    let url = format!("{base}/lib");
488
    assert!(Repo::clone(&url, &root.join("early"))
489
        .err()
490
        .unwrap()
491
        .to_string()
492
        .contains("unbound"));
493
494
    // An existing repository with its own id and history.
495
    let work = root.join("work");
496
    let mut local = Repo::init(&work).unwrap();
497
    let my_id = local.id().unwrap();
498
    write(&work, "a.txt", b"a\n");
499
    local.snapshot("test").unwrap();
500
    local.commit("a", &[]).unwrap();
501
    local.config.set("remote.origin.url", &url).unwrap();
502
    local.save_config().unwrap();
503
    assert!(
504
        local
505
            .fetch("origin")
506
            .err()
507
            .unwrap()
508
            .to_string()
509
            .contains("unbound"),
510
        "fetching an unbound remote is refused"
511
    );
512
    let results = local.push("origin", false).unwrap();
513
    assert!(results.iter().all(|r| r.ok), "{results:?}");
514
515
    let hosted = Repo::open(&served.join("lib")).unwrap();
516
    assert!(!hosted.is_unbound());
517
    assert_eq!(hosted.id().unwrap(), my_id, "bound to the pusher's id");
518
    assert_eq!(hosted.bookmark_heads().unwrap().len(), 1);
519
    // From now on it is an ordinary remote: clones share the id, other repositories are refused.
520
    let cloned = Repo::clone(&url, &root.join("late")).unwrap();
521
    assert_eq!(cloned.id().unwrap(), my_id);
522
    let mut other = Repo::init(&root.join("other")).unwrap();
523
    other.config.set("remote.origin.url", &url).unwrap();
524
    other.save_config().unwrap();
525
    write(&root.join("other"), "b.txt", b"b\n");
526
    other.snapshot("test").unwrap();
527
    other.commit("b", &[]).unwrap();
528
    assert!(other
529
        .push("origin", false)
530
        .err()
531
        .unwrap()
532
        .to_string()
533
        .contains("different repository"));
534
}
535
536
/// History made before an identity existed (zero author) is adopted by
537
/// the pusher's seal, so it passes a server that enforces a policy.
538
#[test]
539
fn anonymous_history_is_adopted_by_the_pushers_seal() {
540
    hermetic();
541
    let dir = tempfile::tempdir().unwrap();
542
    let root = dir.path();
543
    let served = root.join("served");
544
    Repo::init_bare_unbound(&served.join("app")).unwrap();
545
    let base = start(&served, vec![]);
546
    let url = format!("{base}/app");
547
548
    // Two anonymous changes, then an identity and a policy naming it.
549
    let work = root.join("work");
550
    let mut local = Repo::init(&work).unwrap();
551
    write(&work, "a.txt", b"a\n");
552
    local.snapshot("test").unwrap();
553
    let anon = local.commit("before identity", &[]).unwrap();
554
    local
555
        .create_identity(
556
            "Andy",
557
            "[email protected]",
558
            oxy_core::repo::IdentityScope::Repo,
559
        )
560
        .unwrap();
561
    local.policy_init().unwrap();
562
    write(&work, "b.txt", b"b\n");
563
    local.snapshot("test").unwrap();
564
    let mine = local.commit("after identity", &[]).unwrap();
565
    assert!(matches!(
566
        local.authenticate_change(&anon).unwrap(),
567
        SignatureStatus::Unsigned
568
    ));
569
    local.config.set("remote.origin.url", &url).unwrap();
570
    local.save_config().unwrap();
571
    let results = local.push("origin", false).unwrap();
572
    assert!(results.iter().all(|r| r.ok), "{results:?}");
573
574
    // The server holds the policy and both changes verify: sealed by the adopter.
575
    let hosted = Repo::open(&served.join("app")).unwrap();
576
    assert!(hosted.current_policy().unwrap().is_some());
577
    for h in [anon, mine] {
578
        assert!(
579
            matches!(hosted.authenticate_change(&h).unwrap(), SignatureStatus::Valid { sealed: true, name, .. } if name == "Andy"),
580
            "{h}"
581
        );
582
    }
583
    // A change that names another author still cannot be sealed by someone else.
584
    let stranger = root.join("stranger");
585
    let mut other = Repo::init(&stranger).unwrap();
586
    other
587
        .create_identity(
588
            "Mallory",
589
            "[email protected]",
590
            oxy_core::repo::IdentityScope::Repo,
591
        )
592
        .unwrap();
593
    write(&stranger, "c.txt", b"c\n");
594
    other.snapshot("test").unwrap();
595
    let theirs = other.commit("mallory's", &[]).unwrap();
596
    assert!(matches!(
597
        other.authenticate_change(&theirs).unwrap(),
598
        SignatureStatus::Unsigned
599
    ));
600
    let bundle = other.bundle_for(&[theirs]).unwrap();
601
    local.import_bundle(&bundle, false).unwrap();
602
    local.seal(&[theirs]).unwrap();
603
    assert!(
604
        matches!(local.authenticate_change(&theirs).unwrap(), SignatureStatus::Invalid(why) if why.contains("neither the author nor a delegate"))
605
    );
606
}