~yolanda.robla/ubuntu/trusty/nodejs/add_distribution

« back to all changes in this revision

Viewing changes to test/simple/test-tls-check-server-identity.js

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright Joyent, Inc. and other Node contributors.
 
2
//
 
3
// Permission is hereby granted, free of charge, to any person obtaining a
 
4
// copy of this software and associated documentation files (the
 
5
// "Software"), to deal in the Software without restriction, including
 
6
// without limitation the rights to use, copy, modify, merge, publish,
 
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
 
8
// persons to whom the Software is furnished to do so, subject to the
 
9
// following conditions:
 
10
//
 
11
// The above copyright notice and this permission notice shall be included
 
12
// in all copies or substantial portions of the Software.
 
13
//
 
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
 
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
 
21
 
 
22
var common = require('../common');
 
23
var assert = require('assert');
 
24
var util = require('util');
 
25
var tls = require('tls');
 
26
 
 
27
var tests = [
 
28
  // Basic CN handling
 
29
  { host: 'a.com', cert: { subject: { CN: 'a.com' } }, result: true },
 
30
  { host: 'a.com', cert: { subject: { CN: 'A.COM' } }, result: true },
 
31
  { host: 'a.com', cert: { subject: { CN: 'b.com' } }, result: false },
 
32
  { host: 'a.com', cert: { subject: { CN: 'a.com.' } }, result: true },
 
33
 
 
34
  // Wildcards in CN
 
35
  { host: 'b.a.com', cert: { subject: { CN: '*.a.com' } }, result: true },
 
36
  { host: 'b.a.com', cert: {
 
37
    subjectaltname: 'DNS:omg.com',
 
38
    subject: { CN: '*.a.com' } },
 
39
    result: false
 
40
  },
 
41
 
 
42
  // Multiple CN fields
 
43
  {
 
44
    host: 'foo.com', cert: {
 
45
      subject: { CN: ['foo.com', 'bar.com'] } // CN=foo.com; CN=bar.com;
 
46
    },
 
47
    result: true
 
48
  },
 
49
 
 
50
  // DNS names and CN
 
51
  {
 
52
    host: 'a.com', cert: {
 
53
      subjectaltname: 'DNS:*',
 
54
      subject: { CN: 'b.com' }
 
55
    },
 
56
    result: false
 
57
  },
 
58
  {
 
59
    host: 'a.com', cert: {
 
60
      subjectaltname: 'DNS:*.com',
 
61
      subject: { CN: 'b.com' }
 
62
    },
 
63
    result: false
 
64
  },
 
65
  {
 
66
    host: 'a.co.uk', cert: {
 
67
      subjectaltname: 'DNS:*.co.uk',
 
68
      subject: { CN: 'b.com' }
 
69
    },
 
70
    result: true
 
71
  },
 
72
  {
 
73
    host: 'a.com', cert: {
 
74
      subjectaltname: 'DNS:*.a.com',
 
75
      subject: { CN: 'a.com' }
 
76
    },
 
77
    result: false
 
78
  },
 
79
  {
 
80
    host: 'a.com', cert: {
 
81
      subjectaltname: 'DNS:*.a.com',
 
82
      subject: { CN: 'b.com' }
 
83
    },
 
84
    result: false
 
85
  },
 
86
  {
 
87
    host: 'a.com', cert: {
 
88
      subjectaltname: 'DNS:a.com',
 
89
      subject: { CN: 'b.com' }
 
90
    },
 
91
    result: true
 
92
  },
 
93
  {
 
94
    host: 'a.com', cert: {
 
95
      subjectaltname: 'DNS:A.COM',
 
96
      subject: { CN: 'b.com' }
 
97
    },
 
98
    result: true
 
99
  },
 
100
 
 
101
  // DNS names
 
102
  {
 
103
    host: 'a.com', cert: {
 
104
      subjectaltname: 'DNS:*.a.com',
 
105
      subject: {}
 
106
    },
 
107
    result: false
 
108
  },
 
109
  {
 
110
    host: 'b.a.com', cert: {
 
111
      subjectaltname: 'DNS:*.a.com',
 
112
      subject: {}
 
113
    },
 
114
    result: true
 
115
  },
 
116
  {
 
117
    host: 'c.b.a.com', cert: {
 
118
      subjectaltname: 'DNS:*.a.com',
 
119
      subject: {}
 
120
    },
 
121
    result: false
 
122
  },
 
123
  {
 
124
    host: 'b.a.com', cert: {
 
125
      subjectaltname: 'DNS:*b.a.com',
 
126
      subject: {}
 
127
    },
 
128
    result: true
 
129
  },
 
130
  {
 
131
    host: 'a-cb.a.com', cert: {
 
132
      subjectaltname: 'DNS:*b.a.com',
 
133
      subject: {}
 
134
    },
 
135
    result: true
 
136
  },
 
137
  {
 
138
    host: 'a.b.a.com', cert: {
 
139
      subjectaltname: 'DNS:*b.a.com',
 
140
      subject: {}
 
141
    },
 
142
    result: false
 
143
  },
 
144
  // Mutliple DNS names
 
145
  {
 
146
    host: 'a.b.a.com', cert: {
 
147
      subjectaltname: 'DNS:*b.a.com, DNS:a.b.a.com',
 
148
      subject: {}
 
149
    },
 
150
    result: true
 
151
  },
 
152
  // URI names
 
153
  {
 
154
    host: 'a.b.a.com', cert: {
 
155
      subjectaltname: 'URI:http://a.b.a.com/',
 
156
      subject: {}
 
157
    },
 
158
    result: true
 
159
  },
 
160
  {
 
161
    host: 'a.b.a.com', cert: {
 
162
      subjectaltname: 'URI:http://*.b.a.com/',
 
163
      subject: {}
 
164
    },
 
165
    result: false
 
166
  },
 
167
  // IP addresses
 
168
  {
 
169
    host: 'a.b.a.com', cert: {
 
170
      subjectaltname: 'IP Address:127.0.0.1',
 
171
      subject: {}
 
172
    },
 
173
    result: false
 
174
  },
 
175
  {
 
176
    host: '127.0.0.1', cert: {
 
177
      subjectaltname: 'IP Address:127.0.0.1',
 
178
      subject: {}
 
179
    },
 
180
    result: true
 
181
  },
 
182
  {
 
183
    host: '127.0.0.2', cert: {
 
184
      subjectaltname: 'IP Address:127.0.0.1',
 
185
      subject: {}
 
186
    },
 
187
    result: false
 
188
  },
 
189
  {
 
190
    host: '127.0.0.1', cert: {
 
191
      subjectaltname: 'DNS:a.com',
 
192
      subject: {}
 
193
    },
 
194
    result: false
 
195
  },
 
196
  {
 
197
    host: 'localhost', cert: {
 
198
      subjectaltname: 'DNS:a.com',
 
199
      subject: { CN: 'localhost' }
 
200
    },
 
201
    result: false
 
202
  },
 
203
];
 
204
 
 
205
tests.forEach(function(test, i) {
 
206
  assert.equal(tls.checkServerIdentity(test.host, test.cert),
 
207
               test.result,
 
208
               'Test#' + i + ' failed: ' + util.inspect(test));
 
209
});