[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [Git][tpo/applications/tor-browser][tor-browser-156.0a1-17.0-2] fixup! TB 44806: Implement the tor integration in Rust.



Title: GitLab

Pier Angelo Vendrame pushed to branch tor-browser-156.0a1-17.0-2 at The Tor Project / Applications / Tor Browser

Commits:

  • bf25a489
    by Pier Angelo Vendrame at 2026-11-18T08:56:15+01:00
    fixup! TB 44806: Implement the tor integration in Rust.
    
    Fix adapters test and set the test tag.
    

2 changed files:

Changes:

  • toolkit/components/tor-integration/test/xpcshell/test_adapters.js
    ... ... @@ -3,49 +3,62 @@
    3 3
     
    
    4 4
     "use strict";
    
    5 5
     
    
    6
    -const { OxidationAdapters, PromisifiedCallback } = ChromeUtils.importESModule(
    
    6
    +const { OxidationAdapters, promisifyMethod } = ChromeUtils.importESModule(
    
    7 7
       "moz-src:///toolkit/components/tor-integration/OxidationAdapters.sys.mjs"
    
    8 8
     );
    
    9 9
     
    
    10
    +/**
    
    11
    + * The object that contains the method we want to promisiefy with
    
    12
    + * promisifyMethod.
    
    13
    + */
    
    14
    +class MockObject {
    
    15
    +  #func;
    
    16
    +  constructor(func) {
    
    17
    +    this.#func = func;
    
    18
    +  }
    
    19
    +  testMethod() {
    
    20
    +    this.#func(...arguments);
    
    21
    +  }
    
    22
    +}
    
    23
    +
    
    10 24
     add_task(async function test_callback_happy() {
    
    11 25
       {
    
    12
    -    const cb = new PromisifiedCallback();
    
    13
    -    cb.onReply("");
    
    14
    -    Assert.strictEqual(await cb.promise, undefined);
    
    26
    +    const obj = new MockObject(cb => cb.onReply(""));
    
    27
    +    Assert.strictEqual(await promisifyMethod(obj, "testMethod"), undefined);
    
    15 28
       }
    
    16 29
       {
    
    17
    -    const cb = new PromisifiedCallback();
    
    18
    -    cb.onReply("1234");
    
    19
    -    Assert.strictEqual(await cb.promise, 1234);
    
    30
    +    const obj = new MockObject(cb => cb.onReply("1234"));
    
    31
    +    Assert.strictEqual(await promisifyMethod(obj, "testMethod"), 1234);
    
    20 32
       }
    
    21 33
       {
    
    22
    -    const cb = new PromisifiedCallback();
    
    23
    -    cb.onReply('"1234"');
    
    24
    -    Assert.strictEqual(await cb.promise, "1234");
    
    34
    +    const obj = new MockObject(cb => cb.onReply('"1234"'));
    
    35
    +    Assert.strictEqual(await promisifyMethod(obj, "testMethod"), "1234");
    
    25 36
       }
    
    26 37
       {
    
    27
    -    const cb = new PromisifiedCallback();
    
    28
    -    cb.onReply('"a string"');
    
    29
    -    Assert.strictEqual(await cb.promise, "a string");
    
    38
    +    const obj = new MockObject(cb => cb.onReply('"a string"'));
    
    39
    +    Assert.strictEqual(await promisifyMethod(obj, "testMethod"), "a string");
    
    30 40
       }
    
    31 41
       {
    
    32
    -    const cb = new PromisifiedCallback();
    
    33
    -    cb.onReply('["an", "array"]');
    
    34
    -    Assert.deepEqual(await cb.promise, ["an", "array"]);
    
    42
    +    const obj = new MockObject(cb => cb.onReply('"\\"a string\\""'));
    
    43
    +    Assert.strictEqual(await promisifyMethod(obj, "testMethod"), '"a string"');
    
    35 44
       }
    
    36 45
       {
    
    37
    -    const cb = new PromisifiedCallback();
    
    38
    -    cb.onReply('{"an": "object"}');
    
    39
    -    Assert.deepEqual(await cb.promise, { an: "object" });
    
    46
    +    const obj = new MockObject(cb => cb.onReply('["an", "array"]'));
    
    47
    +    Assert.deepEqual(await promisifyMethod(obj, "testMethod"), ["an", "array"]);
    
    48
    +  }
    
    49
    +  {
    
    50
    +    const obj = new MockObject(cb => cb.onReply('{"an": "object"}'));
    
    51
    +    Assert.deepEqual(await promisifyMethod(obj, "testMethod"), {
    
    52
    +      an: "object",
    
    53
    +    });
    
    40 54
       }
    
    41 55
     });
    
    42 56
     
    
    43 57
     add_task(async function test_callback_tor_error() {
    
    44 58
       let hadError = false;
    
    45 59
       try {
    
    46
    -    const cb = new PromisifiedCallback();
    
    47
    -    cb.onTorError(400, "Some error message");
    
    48
    -    await cb.promise;
    
    60
    +    const obj = new MockObject(cb => cb.onTorError(400, "Some error message"));
    
    61
    +    await promisifyMethod(obj, "testMethod");
    
    49 62
       } catch (e) {
    
    50 63
         hadError = true;
    
    51 64
         Assert.equal(e.code, 400);
    
    ... ... @@ -58,9 +71,8 @@ add_task(async function test_callback_generic_error() {
    58 71
       const message = "A more specific error message, maybe not machine-friendly.";
    
    59 72
       let hadError = false;
    
    60 73
       try {
    
    61
    -    const cb = new PromisifiedCallback();
    
    62
    -    cb.onGenericError(message);
    
    63
    -    await cb.promise;
    
    74
    +    const obj = new MockObject(cb => cb.onGenericError(message));
    
    75
    +    await promisifyMethod(obj, "testMethod");
    
    64 76
       } catch (e) {
    
    65 77
         hadError = true;
    
    66 78
         Assert.equal(e.message, message);
    
    ... ... @@ -68,6 +80,39 @@ add_task(async function test_callback_generic_error() {
    68 80
       Assert.ok(hadError, "We did not get an error, but we expected one.");
    
    69 81
     });
    
    70 82
     
    
    83
    +add_task(async function test_callback_arguments() {
    
    84
    +  {
    
    85
    +    const obj = new MockObject((arg, cb) => {
    
    86
    +      Assert.equal(arg, 123);
    
    87
    +      cb.onReply("");
    
    88
    +    });
    
    89
    +    await promisifyMethod(obj, "testMethod", 123);
    
    90
    +  }
    
    91
    +  {
    
    92
    +    const obj = new MockObject((arg, cb) => {
    
    93
    +      Assert.equal(arg, "a string");
    
    94
    +      cb.onReply("");
    
    95
    +    });
    
    96
    +    await promisifyMethod(obj, "testMethod", "a string");
    
    97
    +  }
    
    98
    +  {
    
    99
    +    const obj = new MockObject((arg1, arg2, cb) => {
    
    100
    +      Assert.equal(arg1, 123);
    
    101
    +      Assert.equal(arg2, "a string");
    
    102
    +      cb.onReply("");
    
    103
    +    });
    
    104
    +    await promisifyMethod(obj, "testMethod", 123, "a string");
    
    105
    +  }
    
    106
    +  {
    
    107
    +    const bridges = ["bridge", "line", "obfs4 192.168.1.5:443"];
    
    108
    +    const obj = new MockObject((arg, cb) => {
    
    109
    +      Assert.deepEqual(arg, bridges);
    
    110
    +      cb.onReply("");
    
    111
    +    });
    
    112
    +    await promisifyMethod(obj, "testMethod", bridges);
    
    113
    +  }
    
    114
    +});
    
    115
    +
    
    71 116
     add_task(function test_adapter_circuit() {
    
    72 117
       Assert.deepEqual(
    
    73 118
         OxidationAdapters.convertCircuit({
    
    ... ... @@ -253,36 +298,36 @@ add_task(function test_adapter_pluggable_transports() {
    253 298
         OxidationAdapters.convertPluggableTransports([
    
    254 299
           {
    
    255 300
             transports: ["obfs4", "meek_lite"],
    
    256
    -        type: "exec",
    
    257
    -        pathToBinary: "TorBrowser/Tor/PluggableTransports/lyrebird",
    
    301
    +        pt_type: "exec",
    
    302
    +        path_to_binary: "TorBrowser/Tor/PluggableTransports/lyrebird",
    
    258 303
           },
    
    259 304
           {
    
    260 305
             transports: ["snowflake"],
    
    261
    -        type: "exec",
    
    262
    -        pathToBinary: "TorBrowser/Tor/PluggableTransports/lyrebird",
    
    306
    +        pt_type: "exec",
    
    307
    +        path_to_binary: "TorBrowser/Tor/PluggableTransports/lyrebird",
    
    263 308
             options: "some=option",
    
    264 309
             ip: null,
    
    265 310
             port: null,
    
    266 311
           },
    
    267 312
           {
    
    268 313
             transports: ["conjure"],
    
    269
    -        type: "exec",
    
    270
    -        pathToBinary: "TorBrowser/Tor/PluggableTransports/conjure-client",
    
    314
    +        pt_type: "exec",
    
    315
    +        path_to_binary: "TorBrowser/Tor/PluggableTransports/conjure-client",
    
    271 316
             // Ignored even when not null.
    
    272 317
             ip: "10.0.2.2",
    
    273 318
             port: 80,
    
    274 319
           },
    
    275 320
           {
    
    276 321
             transports: ["proxy1"],
    
    277
    -        type: "socks4",
    
    278
    -        pathToBinary: null,
    
    322
    +        pt_type: "socks4",
    
    323
    +        path_to_binary: null,
    
    279 324
             ip: "10.0.2.2",
    
    280 325
             port: 80,
    
    281 326
           },
    
    282 327
           {
    
    283 328
             transports: ["proxy2"],
    
    284
    -        type: "socks5",
    
    285
    -        pathToBinary: "an/ignored/binary",
    
    329
    +        pt_type: "socks5",
    
    330
    +        path_to_binary: "an/ignored/binary",
    
    286 331
             ip: "[::1]",
    
    287 332
             port: 80,
    
    288 333
           },
    

  • toolkit/components/tor-integration/test/xpcshell/xpcshell.toml
    1 1
     [DEFAULT]
    
    2 2
     head = "head.js"
    
    3
    +tags = "tor"
    
    3 4
     
    
    4 5
     ["test_adapters.js"]
    
    5 6
     
    

  • _______________________________________________
    tor-commits mailing list -- tor-commits@xxxxxxxxxxxxxxxxxxxx
    To unsubscribe send an email to tor-commits-leave@xxxxxxxxxxxxxxxxxxxx