1
1
import { afterAll , beforeAll , describe , expect , it } from "@jest/globals" ;
2
2
import { ORDConfiguration , ORDDocument , ORDV1DocumentDescription } from "@open-resource-discovery/specification" ;
3
3
import path from "path" ;
4
- import {
5
- ORD_DOCUMENTS_SUB_DIRECTORY ,
6
- ORD_DOCUMENTS_URL_PATH ,
7
- ORD_SERVER_PREFIX_PATH ,
8
- WELL_KNOWN_ENDPOINT ,
9
- } from "src/constant.js" ;
4
+ import { PATH_CONSTANTS } from "src/constant.js" ;
10
5
import { OptAuthMethod , OptSourceType } from "src/model/cli.js" ;
11
6
import { ProviderServerOptions , startProviderServer } from "src/server.js" ;
12
7
@@ -29,7 +24,7 @@ describe("Server Integration", () => {
29
24
beforeAll ( async ( ) => {
30
25
const options : ProviderServerOptions = {
31
26
ordDirectory : LOCAL_DIRECTORY ,
32
- ordDocumentsSubDirectory : ORD_DOCUMENTS_SUB_DIRECTORY ,
27
+ ordDocumentsSubDirectory : PATH_CONSTANTS . DOCUMENTS_SUBDIRECTORY ,
33
28
sourceType : OptSourceType . Local ,
34
29
host : TEST_HOST ,
35
30
port : TEST_PORT ,
@@ -49,15 +44,15 @@ describe("Server Integration", () => {
49
44
50
45
describe ( "Well-Known Endpoint" , ( ) => {
51
46
it ( "should return ORD configuration without authentication" , async ( ) => {
52
- const response = await fetch ( `${ SERVER_URL } ${ WELL_KNOWN_ENDPOINT } ` ) ;
47
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . WELL_KNOWN_ENDPOINT } ` ) ;
53
48
54
49
expect ( response . status ) . toBe ( 200 ) ;
55
50
const data = await response . json ( ) ;
56
51
expect ( data ) . toHaveProperty ( "openResourceDiscoveryV1" ) ;
57
52
} ) ;
58
53
59
54
it ( "should list all available documents in configuration" , async ( ) => {
60
- const response = await fetch ( `${ SERVER_URL } ${ WELL_KNOWN_ENDPOINT } ` ) ;
55
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . WELL_KNOWN_ENDPOINT } ` ) ;
61
56
const data = ( await response . json ( ) ) as ORDConfiguration ;
62
57
63
58
expect ( data . openResourceDiscoveryV1 . documents ) . toBeDefined ( ) ;
@@ -73,13 +68,13 @@ describe("Server Integration", () => {
73
68
74
69
describe ( "ORD Documents Endpoint" , ( ) => {
75
70
it ( "should require authentication for accessing documents" , async ( ) => {
76
- const response = await fetch ( `${ SERVER_URL } ${ ORD_DOCUMENTS_URL_PATH } /ref-app-example-1` ) ;
71
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /ref-app-example-1` ) ;
77
72
expect ( response . status ) . toBe ( 401 ) ;
78
73
} ) ;
79
74
80
75
it ( "should return document with valid authentication" , async ( ) => {
81
76
const credentials = Buffer . from ( "admin:secret" ) . toString ( "base64" ) ;
82
- const response = await fetch ( `${ SERVER_URL } ${ ORD_DOCUMENTS_URL_PATH } /ref-app-example-1` , {
77
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /ref-app-example-1` , {
83
78
headers : {
84
79
Authorization : `Basic ${ credentials } ` ,
85
80
} ,
@@ -95,7 +90,7 @@ describe("Server Integration", () => {
95
90
const credentials = Buffer . from ( "admin:secret" ) . toString ( "base64" ) ;
96
91
const headers = { Authorization : `Basic ${ credentials } ` } ;
97
92
98
- const configResponse = await fetch ( `${ SERVER_URL } ${ WELL_KNOWN_ENDPOINT } ` ) ;
93
+ const configResponse = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . WELL_KNOWN_ENDPOINT } ` ) ;
99
94
const config = ( await configResponse . json ( ) ) as ORDConfiguration ;
100
95
const documents = config . openResourceDiscoveryV1 . documents ! ;
101
96
@@ -110,7 +105,7 @@ describe("Server Integration", () => {
110
105
111
106
it ( "should handle document names with special characters" , async ( ) => {
112
107
const credentials = Buffer . from ( "admin:secret" ) . toString ( "base64" ) ;
113
- const response = await fetch ( `${ SERVER_URL } ${ ORD_DOCUMENTS_URL_PATH } /ref-app-example-1` , {
108
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /ref-app-example-1` , {
114
109
headers : {
115
110
Authorization : `Basic ${ credentials } ` ,
116
111
} ,
@@ -121,7 +116,7 @@ describe("Server Integration", () => {
121
116
122
117
it ( "should correctly extract document name when URL contains .json extension" , async ( ) => {
123
118
const credentials = Buffer . from ( "admin:secret" ) . toString ( "base64" ) ;
124
- const response = await fetch ( `${ SERVER_URL } ${ ORD_DOCUMENTS_URL_PATH } /ref-app-example-1.json` , {
119
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /ref-app-example-1.json` , {
125
120
headers : {
126
121
Authorization : `Basic ${ credentials } ` ,
127
122
} ,
@@ -135,7 +130,7 @@ describe("Server Integration", () => {
135
130
136
131
it ( "should correctly extract document name when URL contains dots and a .json extension" , async ( ) => {
137
132
const credentials = Buffer . from ( "admin:secret" ) . toString ( "base64" ) ;
138
- const response = await fetch ( `${ SERVER_URL } ${ ORD_DOCUMENTS_URL_PATH } /sap.ref-app-example.json` , {
133
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /sap.ref-app-example.json` , {
139
134
headers : {
140
135
Authorization : `Basic ${ credentials } ` ,
141
136
} ,
@@ -151,7 +146,7 @@ describe("Server Integration", () => {
151
146
describe ( "Static Resources" , ( ) => {
152
147
it ( "should serve static files with authentication" , async ( ) => {
153
148
const credentials = Buffer . from ( "admin:secret" ) . toString ( "base64" ) ;
154
- const response = await fetch ( `${ SERVER_URL } ${ ORD_SERVER_PREFIX_PATH } /astronomy/v1/openapi/oas3.json` , {
149
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . SERVER_PREFIX } /astronomy/v1/openapi/oas3.json` , {
155
150
headers : {
156
151
Authorization : `Basic ${ credentials } ` ,
157
152
} ,
@@ -171,7 +166,7 @@ describe("Server Integration", () => {
171
166
describe ( "Error Handling" , ( ) => {
172
167
it ( "should return 404 for non-existent documents" , async ( ) => {
173
168
const credentials = Buffer . from ( "admin:secret" ) . toString ( "base64" ) ;
174
- const response = await fetch ( `${ SERVER_URL } ${ ORD_DOCUMENTS_URL_PATH } /non-existent-document` , {
169
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /non-existent-document` , {
175
170
headers : {
176
171
Authorization : `Basic ${ credentials } ` ,
177
172
} ,
@@ -184,7 +179,7 @@ describe("Server Integration", () => {
184
179
185
180
it ( "should return 401 with invalid credentials" , async ( ) => {
186
181
const credentials = Buffer . from ( "admin:wrong" ) . toString ( "base64" ) ;
187
- const response = await fetch ( `${ SERVER_URL } ${ ORD_DOCUMENTS_URL_PATH } /ref-app-example-1` , {
182
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /ref-app-example-1` , {
188
183
headers : {
189
184
Authorization : `Basic ${ credentials } ` ,
190
185
} ,
@@ -195,7 +190,7 @@ describe("Server Integration", () => {
195
190
196
191
it ( "should handle malformed document names gracefully" , async ( ) => {
197
192
const credentials = Buffer . from ( "admin:secret" ) . toString ( "base64" ) ;
198
- const response = await fetch ( `${ SERVER_URL } ${ ORD_DOCUMENTS_URL_PATH } /../../etc/passwd` , {
193
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /../../etc/passwd` , {
199
194
headers : {
200
195
Authorization : `Basic ${ credentials } ` ,
201
196
} ,
@@ -211,7 +206,7 @@ describe("Server Integration", () => {
211
206
beforeAll ( async ( ) => {
212
207
const options : ProviderServerOptions = {
213
208
ordDirectory : LOCAL_DIRECTORY ,
214
- ordDocumentsSubDirectory : ORD_DOCUMENTS_SUB_DIRECTORY ,
209
+ ordDocumentsSubDirectory : PATH_CONSTANTS . DOCUMENTS_SUBDIRECTORY ,
215
210
sourceType : OptSourceType . Local ,
216
211
host : TEST_HOST ,
217
212
port : MULTI_AUTH_PORT ,
@@ -231,7 +226,7 @@ describe("Server Integration", () => {
231
226
232
227
it ( "should accept basic auth when multiple auth methods are configured" , async ( ) => {
233
228
const credentials = Buffer . from ( "admin:secret" ) . toString ( "base64" ) ;
234
- const response = await fetch ( `${ SERVER_URL_2 } ${ ORD_DOCUMENTS_URL_PATH } /ref-app-example-1` , {
229
+ const response = await fetch ( `${ SERVER_URL_2 } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /ref-app-example-1` , {
235
230
headers : {
236
231
Authorization : `Basic ${ credentials } ` ,
237
232
} ,
@@ -244,7 +239,7 @@ describe("Server Integration", () => {
244
239
describe ( "Server Configuration" , ( ) => {
245
240
it ( "should set correct content type headers" , async ( ) => {
246
241
const credentials = Buffer . from ( "admin:secret" ) . toString ( "base64" ) ;
247
- const response = await fetch ( `${ SERVER_URL } ${ ORD_DOCUMENTS_URL_PATH } /ref-app-example-1` , {
242
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /ref-app-example-1` , {
248
243
headers : {
249
244
Authorization : `Basic ${ credentials } ` ,
250
245
} ,
@@ -263,7 +258,7 @@ describe("Server Integration", () => {
263
258
264
259
const requests = Array ( 10 )
265
260
. fill ( null )
266
- . map ( ( ) => fetch ( `${ SERVER_URL } ${ ORD_DOCUMENTS_URL_PATH } /ref-app-example-1` , { headers } ) ) ;
261
+ . map ( ( ) => fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /ref-app-example-1` , { headers } ) ) ;
267
262
268
263
const responses = await Promise . all ( requests ) ;
269
264
responses . forEach ( ( response ) => {
@@ -273,7 +268,7 @@ describe("Server Integration", () => {
273
268
274
269
it ( "should return ETag headers for caching" , async ( ) => {
275
270
const credentials = Buffer . from ( "admin:secret" ) . toString ( "base64" ) ;
276
- const response = await fetch ( `${ SERVER_URL } ${ ORD_DOCUMENTS_URL_PATH } /ref-app-example-1` , {
271
+ const response = await fetch ( `${ SERVER_URL } ${ PATH_CONSTANTS . DOCUMENTS_URL_PATH } /ref-app-example-1` , {
277
272
headers : {
278
273
Authorization : `Basic ${ credentials } ` ,
279
274
} ,
0 commit comments