aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/XmlRpcTest.php
blob: 25dc18646fac54a7c72b395f30902db92ada1583 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

// SPDX-FileCopyrightText: 2024 Eilertsens Kodeknekkeri
// SPDX-FileCopyrightText: 2024 Harald Eilertsen
//
// SPDX-License-Identifier: AGPL-3.0-or-later

namespace VolseNet\Webtrap\Tests\Unit;

use PHPUnit\Framework\TestCase;
use VolseNet\Webtrap\XmlRpcMethod;

class XmlRpcTest extends TestCase
{
    public function testGetUserBlog(): void
    {
        $payload = '<methodCall><methodName>wp.getUsersBlogs</methodName>'
            . '<params><param><value>someuser</value></param>'
            . '<param><value>verysecretpassword</value></param></params></methodCall>';

        $method = XmlRpcMethod::parse($payload);

        $this->assertEquals('wp.getUsersBlogs', $method->name);
        $this->assertEquals(['someuser', 'verysecretpassword'], $method->params);
    }

    public function testShouldNotExpandEntities(): void
    {
        $payload = <<<'XML'
            <!DOCTYPE foo [ <!ENTITY xxx "expanded entity"> ]>
            <methodCall>
                <methodName>&xxx;</methodName>
            </methodCall>
            XML;

        $method = XmlRpcMethod::parse($payload);

        $this->assertNull($method);
    }

    public function testInvalidXMLShouldThrowRuntimeException(): void
    {
        $payload = '<someTag>some content</otherTag>';

        $this->expectException(\RuntimeException::class);

        XmlRpcMethod::parse($payload);
    }
}