1 | 'use strict';
|
2 |
|
3 | var tap = require('tap')
|
4 | , test = tap.test
|
5 | , createNamespace = require('../context.js').createNamespace
|
6 | ;
|
7 |
|
8 | var crypto;
|
9 | try { crypto = require('crypto'); }
|
10 | catch (err) {}
|
11 |
|
12 | if (crypto) {
|
13 | test("continuation-local state with crypto.randomBytes", function (t) {
|
14 | t.plan(1);
|
15 |
|
16 | var namespace = createNamespace('namespace');
|
17 | namespace.run(function () {
|
18 | namespace.set('test', 0xabad1dea);
|
19 |
|
20 | t.test("deflate", function (t) {
|
21 | namespace.run(function () {
|
22 | namespace.set('test', 42);
|
23 | crypto.randomBytes(100, function (err) {
|
24 | if (err) throw err;
|
25 | t.equal(namespace.get('test'), 42, "mutated state was preserved");
|
26 | t.end();
|
27 | });
|
28 | });
|
29 | });
|
30 | });
|
31 | });
|
32 |
|
33 | test("continuation-local state with crypto.pseudoRandomBytes", function (t) {
|
34 | t.plan(1);
|
35 |
|
36 | var namespace = createNamespace('namespace');
|
37 | namespace.run(function () {
|
38 | namespace.set('test', 0xabad1dea);
|
39 |
|
40 | t.test("deflate", function (t) {
|
41 | namespace.run(function () {
|
42 | namespace.set('test', 42);
|
43 | crypto.pseudoRandomBytes(100, function (err) {
|
44 | if (err) throw err;
|
45 | t.equal(namespace.get('test'), 42, "mutated state was preserved");
|
46 | t.end();
|
47 | });
|
48 | });
|
49 | });
|
50 | });
|
51 | });
|
52 |
|
53 | test("continuation-local state with crypto.pbkdf2", function (t) {
|
54 | t.plan(1);
|
55 |
|
56 | var namespace = createNamespace('namespace');
|
57 | namespace.run(function () {
|
58 | namespace.set('test', 0xabad1dea);
|
59 |
|
60 | t.test("deflate", function (t) {
|
61 | namespace.run(function () {
|
62 | namespace.set('test', 42);
|
63 | crypto.pbkdf2("s3cr3tz", "451243", 10, 40, function (err) {
|
64 | if (err) throw err;
|
65 | t.equal(namespace.get('test'), 42, "mutated state was preserved");
|
66 | t.end();
|
67 | });
|
68 | });
|
69 | });
|
70 | });
|
71 | });
|
72 | }
|