@@ -4,6 +4,24 @@ const self = rdapValidator;
4
4
5
5
export default rdapValidator ;
6
6
7
+ self . referenceBase = "https://validator.rdap.org/specs/" ;
8
+
9
+ self . referenceURLs = {
10
+ "rfc7480" : "vanilla/rfc7480.html" ,
11
+ "rfc7481" : "vanilla/rfc7481.html" ,
12
+ "rfc9082" : "vanilla/rfc9082.html" ,
13
+ "rfc9083" : "vanilla/rfc9083.html" ,
14
+ "rfc9224" : "vanilla/rfc9224.html" ,
15
+ "rfc9537" : "vanilla/rfc9537.html" ,
16
+ "feb24-rp" : "gtld/2024-02/rdap-response-profile-21feb24-en.pdf" ,
17
+ "feb24-tig" : "gtld/2024-02/rdap-technical-implementation-guide-21feb24-en.pdf" ,
18
+ "nro" : "rir/2021-01/nro-rdap-profile.txt" ,
19
+ } ;
20
+
21
+ self . ref = function ( f , spec = null ) {
22
+ return self . referenceBase + self . referenceURLs [ spec ?? self . currentSpec ] + "#" + f ;
23
+ }
24
+
7
25
/**
8
26
* Initiate a test run.
9
27
* @param {null|string } url
@@ -12,6 +30,8 @@ export default rdapValidator;
12
30
*/
13
31
self . testURL = function ( url , type , serverType ) {
14
32
33
+ self . currentSpec = "rfc7480" ;
34
+
15
35
self . errors = 0 ;
16
36
17
37
if ( ! self . responseTypes . hasOwnProperty ( type ) ) {
@@ -83,22 +103,26 @@ self.testResponse = function(xhr, url, type, serverType) {
83
103
84
104
if ( ! self . add (
85
105
"error" == type ? xhr . status >= 400 : xhr . status < 400 ,
86
- "HTTP status " + xhr . status + " MUST be " + ( "error" == type ? "> 400 or higher" : "less than 400" )
106
+ "HTTP status " + xhr . status + " MUST be " + ( "error" == type ? "> 400 or higher" : "less than 400" ) ,
107
+ "error" == type ? "section-5.3" : "section-5.1" ,
87
108
) ) return ;
88
109
89
110
if ( ! self . add (
90
111
self . lastTestedResponseHeaders [ "content-type" ] . toLowerCase ( ) . startsWith ( "application/rdap+json" ) ,
91
- "Media type '" + self . lastTestedResponseHeaders [ "content-type" ] + "' SHOULD be is application/rdap+json."
112
+ "Media type '" + self . lastTestedResponseHeaders [ "content-type" ] + "' SHOULD be application/rdap+json." ,
113
+ "section-4.2" ,
92
114
) ) return ;
93
115
94
116
var record ;
95
117
118
+ self . currentSpec = "rfc9083" ;
119
+
96
120
try {
97
121
record = JSON . parse ( xhr . response ?? xhr . responseText ) ;
98
- self . add ( true , "Response body MUST be valid JSON." ) ;
122
+ self . add ( true , "Response body MUST be valid JSON." , "name-introduction" ) ;
99
123
100
124
} catch ( e ) {
101
- self . add ( false , "Response body MUST be valid JSON (parse error: " + e + ")." ) ;
125
+ self . add ( false , "Response body MUST be valid JSON (parse error: " + e + ")." , "name-introduction" ) ;
102
126
103
127
return ;
104
128
}
@@ -107,7 +131,8 @@ self.testResponse = function(xhr, url, type, serverType) {
107
131
108
132
if ( ! self . add (
109
133
self . isObject ( record ) ,
110
- "Response body MUST be a JSON object."
134
+ "Response body MUST be a JSON object." ,
135
+ "section-5" ,
111
136
) ) return ;
112
137
113
138
self . validateRDAPConformance ( record ) ;
@@ -219,16 +244,19 @@ self.validateRDAPConformance = function(record) {
219
244
220
245
if ( self . add (
221
246
record . hasOwnProperty ( "rdapConformance" ) ,
222
- "Record MUST have the 'rdapConformance' property."
247
+ "Record MUST have the 'rdapConformance' property." ,
248
+ "section-4.1" ,
223
249
) ) {
224
250
self . add (
225
251
self . isArray ( record . rdapConformance ) ,
226
- "The 'rdapConformance' property MUST be an array."
252
+ "The 'rdapConformance' property MUST be an array." ,
253
+ "section-4.1" ,
227
254
) ;
228
255
229
256
self . add (
230
257
record . rdapConformance . indexOf ( "rdap_level_0" ) >= 0 ,
231
- "The 'rdapConformance' property MUST contain 'rdap_level_0'."
258
+ "The 'rdapConformance' property MUST contain 'rdap_level_0'." ,
259
+ "section-4.1" ,
232
260
) ;
233
261
}
234
262
@@ -2443,8 +2471,9 @@ self.countryCodes = [
2443
2471
* @param {string } message
2444
2472
* @param {mixed } context
2445
2473
* @param {string } path
2474
+ * @param {string } ref
2446
2475
*/
2447
- self . resultCallback = ( result , message , path ) => null ;
2476
+ self . resultCallback = ( result , message , path , ref ) => null ;
2448
2477
2449
2478
/**
2450
2479
* Specify a callback to invoke when a result has been generated. This callback
@@ -2479,10 +2508,11 @@ self.setTestCompleteCallback = function(callback) {
2479
2508
* Log a result by invoking the resultCallback with the provided arguments.
2480
2509
* @param {bool } result
2481
2510
* @param {string } message
2511
+ * @param {string } ref
2482
2512
*/
2483
- self . add = function ( result , message ) {
2513
+ self . add = function ( result , message , ref ) {
2484
2514
if ( false === result ) self . errors ++ ;
2485
- self . resultCallback ( result , message , self . getPath ( ) ) ;
2515
+ self . resultCallback ( result , message , self . getPath ( ) , ref ? self . ref ( ref ) : undefined ) ;
2486
2516
return result ;
2487
2517
} ;
2488
2518
0 commit comments