mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-04 02:57:11 +09:00
* Plesk module creates the account, the subscription but the plan i... Server_Manager_Plesk::createSubscriptionProps() built the webspace add/set request from custom hosting/limits/permissions values but never told Plesk which service plan to assign, so accounts were provisioned outside of any named plan; the fix adds the FOSSBilling hosting plan's name as the request's plan-name, matching how every other adapter (CWP, DirectAdmin, Hestia, WHM) already passes the package name through. * 🐛 Don't send plan-name on Plesk subscription updates CodeRabbit correctly flagged that Plesk's webspace/set schema has no plan-related node at all (unlike add, which supports plan-name/plan-id/plan-guid/plan-external-id). Sending plan-name through changeAccountPackage() -> webspace/set would have hit the same XSD-sequence rejection as the original ordering bug, just for a different reason -- an element Plesk doesn't recognize there at all. plan-name now stays scoped to the add path only, matching the same conditional pattern already used for htype. Changing an existing subscription's assigned plan isn't supported by this code path; that would need a separate switch-subscription operation (plan-guid/plan-external-id), which is out of scope for #2799. --------- Co-authored-by: Adam Daley <admdly@users.noreply.github.com>
110 lines
4.7 KiB
PHP
110 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
function invokePleskCreateSubscriptionProps(Server_Manager_Plesk $manager, Server_Account $account, string $action): array
|
|
{
|
|
$reflection = new ReflectionClass($manager);
|
|
$method = $reflection->getMethod('createSubscriptionProps');
|
|
|
|
return $method->invokeArgs($manager, [$account, $action]);
|
|
}
|
|
|
|
beforeEach(function (): void {
|
|
$this->manager = new Server_Manager_Plesk([
|
|
'host' => 'plesk.example.com',
|
|
'username' => 'admin',
|
|
'password' => 'secret',
|
|
]);
|
|
|
|
$this->account = (new Server_Account())
|
|
->setUsername('example')
|
|
->setDomain('example.com')
|
|
->setIp('192.0.2.10')
|
|
->setPassword('secret')
|
|
->setClient(new Server_Client())
|
|
->setPackage((new Server_Package())->setName('Business Hosting'));
|
|
});
|
|
|
|
test('createSubscriptionProps sends the settings directly under <add>, in schema order', function (): void {
|
|
$props = invokePleskCreateSubscriptionProps($this->manager, $this->account, 'add');
|
|
|
|
expect($props)->toHaveKey('add')
|
|
->and(array_keys($props['add']))->toBe(['gen_setup', 'hosting', 'limits', 'permissions', 'plan-name'])
|
|
->and($props['add'])->not->toHaveKey('filter')
|
|
->and($props['add'])->not->toHaveKey('values');
|
|
});
|
|
|
|
test('createSubscriptionProps includes htype in gen_setup for the add action', function (): void {
|
|
$props = invokePleskCreateSubscriptionProps($this->manager, $this->account, 'add');
|
|
|
|
expect(array_keys($props['add']['gen_setup']))->toBe(['name', 'owner-login', 'htype', 'ip_address'])
|
|
->and($props['add']['gen_setup']['htype'])->toBe('vrt_hst');
|
|
});
|
|
|
|
test('createSubscriptionProps wraps the set action in filter and values, as Plesk requires', function (): void {
|
|
$props = invokePleskCreateSubscriptionProps($this->manager, $this->account, 'set');
|
|
|
|
expect($props)->toHaveKey('set')
|
|
->and(array_keys($props['set']))->toBe(['filter', 'values'])
|
|
->and(array_keys($props['set']['values']))->toBe(['gen_setup', 'hosting', 'limits', 'permissions']);
|
|
});
|
|
|
|
test('createSubscriptionProps filters the set action by domain name, not owner-login', function (): void {
|
|
$props = invokePleskCreateSubscriptionProps($this->manager, $this->account, 'set');
|
|
|
|
// 'owner-login' would match every webspace this customer owns, applying $values to all of
|
|
// them; 'name' (the domain) scopes the update to this one subscription.
|
|
expect($props['set']['filter'])->toBe(['name' => 'example.com']);
|
|
});
|
|
|
|
test('createSubscriptionProps omits htype from gen_setup for the set action', function (): void {
|
|
$props = invokePleskCreateSubscriptionProps($this->manager, $this->account, 'set');
|
|
|
|
expect($props['set']['values']['gen_setup'])->not->toHaveKey('htype');
|
|
});
|
|
|
|
test('createSubscriptionProps uses custom package limits and permissions', function (): void {
|
|
$this->account->getPackage()->setCustomValues([
|
|
'aftp' => 'true',
|
|
'cron' => '1',
|
|
'nemailml' => '25',
|
|
'spam' => 'yes',
|
|
'ssh' => 'on',
|
|
]);
|
|
|
|
$props = invokePleskCreateSubscriptionProps($this->manager, $this->account, 'add');
|
|
$limits = array_column($props['add']['limits']['limit'], 'value', 'name');
|
|
$permissions = array_column($props['add']['permissions']['permission'], 'value', 'name');
|
|
|
|
expect($limits['max_maillists'])->toBe('25')
|
|
->and($permissions['manage_crontab'])->toBe('true')
|
|
->and($permissions['manage_anonftp'])->toBe('true')
|
|
->and($permissions['manage_maillists'])->toBe('true')
|
|
->and($permissions['manage_not_chroot_shell'])->toBe('true')
|
|
->and($permissions['manage_spamfilter'])->toBe('true');
|
|
});
|
|
|
|
test('createSubscriptionProps disables mailing lists when the custom limit is zero', function (): void {
|
|
$this->account->getPackage()->setCustomValue('nemailml', '0');
|
|
|
|
$props = invokePleskCreateSubscriptionProps($this->manager, $this->account, 'add');
|
|
$limits = array_column($props['add']['limits']['limit'], 'value', 'name');
|
|
$permissions = array_column($props['add']['permissions']['permission'], 'value', 'name');
|
|
|
|
expect($limits['max_maillists'])->toBe(0)
|
|
->and($permissions['manage_maillists'])->toBe('false');
|
|
});
|
|
|
|
test('createSubscriptionProps assigns the hosting plan name to the Plesk subscription on creation', function (): void {
|
|
$props = invokePleskCreateSubscriptionProps($this->manager, $this->account, 'add');
|
|
|
|
expect($props['add']['plan-name'])->toBe('Business Hosting');
|
|
});
|
|
|
|
test('createSubscriptionProps does not send plan-name on updates, since webspace/set has no plan node', function (): void {
|
|
$props = invokePleskCreateSubscriptionProps($this->manager, $this->account, 'set');
|
|
|
|
expect($props['set']['values'])->not->toHaveKey('plan-name');
|
|
});
|