Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4145789
mediawiki.ForeignApi.test.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
mediawiki.ForeignApi.test.js
View Options
QUnit
.
module
(
'mediawiki.ForeignApi'
,
(
hooks
)
=>
{
const
CoreForeignApi
=
require
(
'mediawiki.ForeignApi.core'
).
ForeignApi
;
hooks
.
beforeEach
(
function
()
{
this
.
server
=
this
.
sandbox
.
useFakeServer
();
this
.
server
.
respondImmediately
=
true
;
// Display debug errors from mw.Api, because the default exception value is
// a useless "http" with details like "404 Not Found" hidden in secondary arguments
// that require a custom Deferred handler, or mw.log.
this
.
sandbox
.
stub
(
mw
,
'log'
,
mw
.
log
.
warn
);
}
);
QUnit
.
test
(
'origin is included in GET requests'
,
async
function
(
assert
)
{
this
.
server
.
respondWith
(
'GET'
,
/origin=/
,
[
200
,
{
'Content-Type'
:
'application/json'
},
'[]'
]
);
const
api
=
new
CoreForeignApi
(
'//example.test/w/api.php'
);
const
res
=
await
api
.
get
(
{}
);
assert
.
deepEqual
(
res
,
[],
'result'
);
}
);
QUnit
.
test
(
'origin is included in POST requests'
,
async
function
(
assert
)
{
this
.
server
.
respondWith
(
'POST'
,
/origin=/
,
[
200
,
{
'Content-Type'
:
'application/json'
},
'[]'
]
);
const
api
=
new
CoreForeignApi
(
'//example.test/w/api.php'
);
const
res
=
await
api
.
post
(
{}
);
assert
.
deepEqual
(
res
,
[],
'result'
);
const
{
requestBody
}
=
this
.
server
.
requests
[
0
];
assert
.
true
(
/origin=/
.
test
(
requestBody
),
'origin is included in POST request body'
);
}
);
QUnit
.
test
(
'origin is not included in same-origin GET requests'
,
async
function
(
assert
)
{
this
.
server
.
respond
(
[
200
,
{
'Content-Type'
:
'application/json'
},
'[]'
]
);
const
api
=
new
CoreForeignApi
(
location
.
origin
+
'/w/api.php'
);
const
res
=
await
api
.
get
(
{}
);
assert
.
deepEqual
(
res
,
[],
'result'
);
const
{
url
}
=
this
.
server
.
requests
[
0
];
assert
.
strictEqual
(
url
.
match
(
/origin=.*?(?:&|$)/
),
null
,
'origin is not included in GET requests'
);
}
);
QUnit
.
test
(
'origin is not included in same-origin POST requests'
,
async
function
(
assert
)
{
this
.
server
.
respond
(
[
200
,
{
'Content-Type'
:
'application/json'
},
'[]'
]
);
const
api
=
new
CoreForeignApi
(
location
.
origin
+
'/w/api.php'
);
const
res
=
await
api
.
post
(
{}
);
assert
.
deepEqual
(
res
,
[],
'result'
);
const
{
requestBody
,
url
}
=
this
.
server
.
requests
[
0
];
assert
.
strictEqual
(
requestBody
.
match
(
/origin=.*?(?:&|$)/
),
null
,
'origin is not included in POST request body'
);
assert
.
strictEqual
(
url
.
match
(
/origin=.*?(?:&|$)/
),
null
,
'origin is not included in POST request URL, either'
);
}
);
}
);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Aug 19 2026, 17:46 (5 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b4/61/eeedd0ee3918330e842225a593fc
Default Alt Text
mediawiki.ForeignApi.test.js (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment