Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions browser-extension/capture/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ docker exec "$CONTAINER" chown -R www-data:www-data /var/www/html/custom_apps/ke
occ app:enable keepiq
occ app:list | sed -n '/Enabled:/,/Disabled:/p' | grep -q ' keepiq:' \
|| { echo "::error::keepiq is not enabled"; exit 1; }
# The web server can still answer 404 for Keepiq's routes for a moment after
# app:enable (it failed one of two identical runs of 4934a642); wait for the
# API before the first real call, which still fails loudly if it never comes.
for _ in $(seq 1 30); do
api GET /api/v1/suites >/dev/null 2>&1 && break
sleep 2
done
# The development vault of admin, which the extension unlocks with "Oj".
suites="$(api GET /api/v1/suites)"
echo "$suites" | grep -q '"status":"active"' \
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Federation/FederatedCopyDeclineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class FederatedCopyDeclineTest extends TestCase {
private ?string $signer = 'cloud.city.example';

protected function setUp(): void {
$this->skipWithoutFederation();
$this->inbound = new FederatedInbound();
$this->inbound->setId('in-1');
$this->inbound->setRecipientUid('bob');
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Federation/FederatedCopyRestoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class FederatedCopyRestoreTest extends TestCase {
private bool $aliceDown = false;

protected function setUp(): void {
$this->skipWithoutFederation();
$this->inbound = new FederatedInbound();
$this->inbound->setId('in-1');
$this->inbound->setRecipientUid('bob');
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Federation/FederatedRemoteChangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class FederatedRemoteChangeTest extends TestCase {
private array $askedWith = [];

protected function setUp(): void {
$this->skipWithoutFederation();
$this->row = new FederatedInbound();
$this->row->setId('in-1');
$this->row->setRecipientUid('bob');
Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Federation/FederatedShareAcceptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class FederatedShareAcceptTest extends TestCase {
private IOCMDiscoveryService&MockObject $ocm;

protected function setUp(): void {
$this->skipWithoutFederation();
$this->pending = new FederatedInbound();
$this->pending->setId('in-1');
$this->pending->setRecipientUid('bob');
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Federation/FederatedShareReceiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@
class FederatedShareReceiveTest extends TestCase {
use FederationFixtures;

/**
* Skip on a Nextcloud without the OCM APIs.
*
* @return void
*/
protected function setUp(): void {
$this->skipWithoutFederation();
}//end setUp()

/** @var array<string,FederatedInbound> */
private array $rows = [];

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Federation/FederatedShareSendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class FederatedShareSendTest extends TestCase {
private ICloudFederationProviderManager&MockObject $ocm;

protected function setUp(): void {
$this->skipWithoutFederation();
$this->source = new Secret();
$this->source->setId('src');
$this->source->setName('Supplier portal');
Expand Down
16 changes: 16 additions & 0 deletions tests/Unit/Federation/FederationFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,28 @@
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Federation\ICloudId;
use OCP\Federation\ICloudIdManager;
use OCP\OCM\Events\OCMEndpointRequestEvent;
use PHPUnit\Framework\TestCase;

trait FederationFixtures {
/** This instance's host. */
private string $localHost = 'cloud.here.example';

/**
* Skip on a Nextcloud that cannot federate.
*
* The OCM APIs these tests use arrived in Nextcloud 33; Keepiq supports 32,
* where FederationRootService::isSupported() is false and federation stays
* off. The same check decides both.
*
* @return void
*/
private function skipWithoutFederation(): void {
if (class_exists(OCMEndpointRequestEvent::class) === false) {
$this->markTestSkipped('Federation needs the OCM APIs of Nextcloud 33 or later.');
}
}//end skipWithoutFederation()

/**
* A partner mapper over an in-memory list.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Federation/FederationLookupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@
class FederationLookupTest extends TestCase {
use FederationFixtures;

/**
* Skip on a Nextcloud without the OCM APIs.
*
* @return void
*/
protected function setUp(): void {
$this->skipWithoutFederation();
}//end setUp()

private IOCMDiscoveryService&MockObject $ocm;

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Federation/FederationOcmRequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@
class FederationOcmRequestListenerTest extends TestCase {
use FederationFixtures;

/**
* Skip on a Nextcloud without the OCM APIs.
*
* @return void
*/
protected function setUp(): void {
$this->skipWithoutFederation();
}//end setUp()

/** @var array<string,string> userId => receive preference */
private array $optIns = ['bob' => '1', 'carol' => '0', 'dave' => '1'];

Expand Down
9 changes: 9 additions & 0 deletions tests/Unit/Federation/FederationPartnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
class FederationPartnerTest extends TestCase {
use FederationFixtures;

/**
* Skip on a Nextcloud without the OCM APIs.
*
* @return void
*/
protected function setUp(): void {
$this->skipWithoutFederation();
}//end setUp()

/** @var array<int,string> URLs the fake HTTP client was asked for */
private array $fetched = [];

Expand Down
63 changes: 62 additions & 1 deletion tests/Unit/Migration/FederatedSharesMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,14 @@ public function testIsANoopWhenEverythingExists(): void {
*/
private function tableDouble(array &$added, bool $exists = false): object {
$type = (new \ReflectionMethod(ISchemaWrapper::class, 'getTable'))->getReturnType();
$class = ($type instanceof \ReflectionNamedType) ? $type->getName() : \stdClass::class;
if ($type instanceof \ReflectionNamedType === false) {
// Nextcloud 34 and older declare no return type, so PHPUnit enforces
// none: a recording object stands in, as a mock of stdClass cannot
// have hasColumn() configured.
return $this->recordingTable(added: $added, exists: $exists);
}

$class = $type->getName();
$mock = $this->getMockBuilder($class)->disableOriginalConstructor()->getMock();
$mock->method('hasColumn')->willReturn($exists);
$addReturn = (new \ReflectionMethod($class, 'addColumn'))->getReturnType();
Expand All @@ -141,4 +148,58 @@ function (string $name, mixed $colType, array $options = []) use (&$added, $addR

return $mock;
}//end tableDouble()

/**
* A plain table stand-in recording addColumn() calls.
*
* @param array<string,array<string,mixed>> $added Receives name => options
* @param bool $exists Whether hasColumn() answers true
*
* @return object
*/
private function recordingTable(array &$added, bool $exists): object {
return new class($added, $exists) {
/** @var array<string,array<string,mixed>> */
private array $added;

/**
* @param array<string,array<string,mixed>> $added
*/
public function __construct(array &$added, private bool $exists) {
$this->added = &$added;
}

public function hasColumn(string $name): bool {
return $this->exists;
}

/**
* @param array<string,mixed> $options
*/
public function addColumn(string $name, mixed $type, array $options = []): void {
$this->added[$name] = $options;
}

/**
* @param array<int,string> $columns
*/
public function setPrimaryKey(array $columns): self {
return $this;
}

/**
* @param array<int,string> $columns
*/
public function addIndex(array $columns, ?string $name = null): self {
return $this;
}

/**
* @param array<int,string> $columns
*/
public function addUniqueIndex(array $columns, ?string $name = null): self {
return $this;
}
};
}//end recordingTable()
}//end class
63 changes: 62 additions & 1 deletion tests/Unit/Migration/SiemConnectorColumnsMigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ public function testIsANoopWhenTheColumnsExist(): void {
*/
private function tableDouble(array &$added, bool $exists = false): object {
$type = (new \ReflectionMethod(ISchemaWrapper::class, 'getTable'))->getReturnType();
$class = ($type instanceof \ReflectionNamedType) ? $type->getName() : \stdClass::class;
if ($type instanceof \ReflectionNamedType === false) {
// Nextcloud 34 and older declare no return type, so PHPUnit enforces
// none: a recording object stands in, as a mock of stdClass cannot
// have hasColumn() configured.
return $this->recordingTable(added: $added, exists: $exists);
}

$class = $type->getName();
$mock = $this->getMockBuilder($class)->disableOriginalConstructor()->getMock();
$mock->method('hasColumn')->willReturn($exists);
$addReturn = (new \ReflectionMethod($class, 'addColumn'))->getReturnType();
Expand All @@ -103,4 +110,58 @@ function (string $name, mixed $colType, array $options = []) use (&$added, $addR
);
return $mock;
}//end tableDouble()

/**
* A plain table stand-in recording addColumn() calls.
*
* @param array<string,array<string,mixed>> $added Receives name => options
* @param bool $exists Whether hasColumn() answers true
*
* @return object
*/
private function recordingTable(array &$added, bool $exists): object {
return new class($added, $exists) {
/** @var array<string,array<string,mixed>> */
private array $added;

/**
* @param array<string,array<string,mixed>> $added
*/
public function __construct(array &$added, private bool $exists) {
$this->added = &$added;
}

public function hasColumn(string $name): bool {
return $this->exists;
}

/**
* @param array<string,mixed> $options
*/
public function addColumn(string $name, mixed $type, array $options = []): void {
$this->added[$name] = $options;
}

/**
* @param array<int,string> $columns
*/
public function setPrimaryKey(array $columns): self {
return $this;
}

/**
* @param array<int,string> $columns
*/
public function addIndex(array $columns, ?string $name = null): self {
return $this;
}

/**
* @param array<int,string> $columns
*/
public function addUniqueIndex(array $columns, ?string $name = null): self {
return $this;
}
};
}//end recordingTable()
}//end class
8 changes: 6 additions & 2 deletions tests/e2e/l10n-browser-catalogue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@ test.describe(`l10n browser catalogue (${APP_ID})`, () => {
if (!bundle) return { registered: false as const, keys: 0 }

// A key whose translation differs from itself — the only kind that can
// tell a working lookup apart from the identity fallback.
// tell a working lookup apart from the identity fallback. Only a plain
// string entry: a plural entry (`_singular_::_plural_`) holds an array
// of forms, always "differs", and resolves through n(), not t().
const translated =
Object.keys(bundle).find((k) => bundle[k] !== k) || null
Object.keys(bundle).find(
(k) => typeof bundle[k] === 'string' && bundle[k] !== k,
) || null
const translate = w.OC?.L10N?.translate || w.t
return {
registered: true as const,
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/workflows/member-overview-offboarding.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ test.describe('Workflow: offboard a leaver from the member overview', () => {
).toBe(1)

await expect(offboarding.getByTestId('offboarding-summary')).toContainText(
'Removed the user from 1 team folders.',
'Removed the user from 1 team folder.',
)

// --- The leaver has no user row in the team folder any more ---
Expand Down
16 changes: 16 additions & 0 deletions tests/e2e/workflows/vault-unlock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ test.describe('Workflow: vault unlock — encryption-suites/spec.md', () => {
// online, which is true in headless Chromium over the instance's
// HTTPS origin.
/\/api\/v1\/passkeys\/login-options\b/,
// LockScreen's checkSuite() asks, whenever online, whether to offer
// "Approve from another device" (#1024). The answer is `{enabled}`,
// an instance switch; no vault material.
/\/api\/v1\/device-approvals\/status\b/,
// When device approval is on, DeviceApprovalRequest on the lock
// screen reads the session user's own recovery enrolment to decide
// whether to offer the administrator path (new-device-approval D6):
// `{enrolled, policy}`, no key material. It fires only on an
// instance with device approval enabled, which CI's is not by
// default; this test timed out before its assertion from #1024 on,
// so neither entry was ever needed until the timeout was fixed.
/\/api\/v1\/recovery\/enrolment$/,
// CnAppRoot's setup() calls useSupportDialog(appId, { persistence:
// 'server' }) unconditionally — same shell layer, and for the same
// reason, as the /api/settings entry above: it runs before any route
Expand Down Expand Up @@ -206,6 +218,10 @@ test.describe('Workflow: vault unlock — encryption-suites/spec.md', () => {

expect(hashes.length).toBeGreaterThan(5)

// Every goto is a full page load: about 4.6 s a route in CI, so the 17
// routes outgrew the default budget at route 15. Scale it with the walk.
test.setTimeout(30_000 + hashes.length * 10_000)

for (const hash of hashes) {
// ADR-074 rule 4, and the note above: `networkidle` never settles on
// Nextcloud, and it was never what caught this bug — the `request`
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/federation/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ for side in a b; do
occ "$side" app:enable keepiq
occ "$side" app:list | sed -n '/Enabled:/,/Disabled:/p' | grep -q ' keepiq:' \
|| { echo "::error::keepiq is not enabled on ${side}"; exit 1; }
# The web server can still answer 404 for Keepiq's routes for a moment
# after app:enable (it failed one of two identical runs of 4934a642); wait
# for the API before the first real call, which still fails loudly if it
# never comes.
for _ in $(seq 1 30); do
api "$side" GET /api/v1/suites >/dev/null 2>&1 && break
sleep 2
done

# The development vault of admin, which the specs unlock with "Oj".
suites="$(api "$side" GET /api/v1/suites)"
Expand Down
Loading