|
|
@ -12,25 +12,30 @@ const String nextcloudVersion = '25.0.1'; |
|
|
|
const String defaultUsername = 'user1'; |
|
|
|
const String defaultUsername = 'user1'; |
|
|
|
const String defaultPassword = 'user1'; |
|
|
|
const String defaultPassword = 'user1'; |
|
|
|
|
|
|
|
|
|
|
|
class TestNextcloudClient extends NextcloudClient { |
|
|
|
class DockerImage { |
|
|
|
TestNextcloudClient( |
|
|
|
DockerImage({ |
|
|
|
super.baseURL, |
|
|
|
required this.name, |
|
|
|
this.containerID, { |
|
|
|
|
|
|
|
super.username, |
|
|
|
|
|
|
|
super.password, |
|
|
|
|
|
|
|
super.language, |
|
|
|
|
|
|
|
super.appType, |
|
|
|
|
|
|
|
super.userAgentOverride, |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
final String containerID; |
|
|
|
final String name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DockerContainer { |
|
|
|
|
|
|
|
DockerContainer({ |
|
|
|
|
|
|
|
required this.id, |
|
|
|
|
|
|
|
required this.port, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final String id; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final int port; |
|
|
|
|
|
|
|
|
|
|
|
Future runOccCommand(final List<String> args) async { |
|
|
|
Future runOccCommand(final List<String> args) async { |
|
|
|
final result = await runExecutableArguments( |
|
|
|
final result = await runExecutableArguments( |
|
|
|
'docker', |
|
|
|
'docker', |
|
|
|
[ |
|
|
|
[ |
|
|
|
'exec', |
|
|
|
'exec', |
|
|
|
containerID, |
|
|
|
id, |
|
|
|
'php', |
|
|
|
'php', |
|
|
|
'-f', |
|
|
|
'-f', |
|
|
|
'occ', |
|
|
|
'occ', |
|
|
@ -48,7 +53,7 @@ class TestNextcloudClient extends NextcloudClient { |
|
|
|
'docker', |
|
|
|
'docker', |
|
|
|
[ |
|
|
|
[ |
|
|
|
'kill', |
|
|
|
'kill', |
|
|
|
containerID, |
|
|
|
id, |
|
|
|
], |
|
|
|
], |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
@ -57,7 +62,7 @@ class TestNextcloudClient extends NextcloudClient { |
|
|
|
'docker', |
|
|
|
'docker', |
|
|
|
[ |
|
|
|
[ |
|
|
|
'logs', |
|
|
|
'logs', |
|
|
|
containerID, |
|
|
|
id, |
|
|
|
], |
|
|
|
], |
|
|
|
stdoutEncoding: utf8, |
|
|
|
stdoutEncoding: utf8, |
|
|
|
)) |
|
|
|
)) |
|
|
@ -66,7 +71,7 @@ class TestNextcloudClient extends NextcloudClient { |
|
|
|
'docker', |
|
|
|
'docker', |
|
|
|
[ |
|
|
|
[ |
|
|
|
'exec', |
|
|
|
'exec', |
|
|
|
containerID, |
|
|
|
id, |
|
|
|
'cat', |
|
|
|
'cat', |
|
|
|
'data/nextcloud.log', |
|
|
|
'data/nextcloud.log', |
|
|
|
], |
|
|
|
], |
|
|
@ -78,147 +83,162 @@ class TestNextcloudClient extends NextcloudClient { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class TestHelper { |
|
|
|
class TestNextcloudClient extends NextcloudClient { |
|
|
|
static Future<String> prepareDockerImage({ |
|
|
|
TestNextcloudClient( |
|
|
|
final List<TestNextcloudUser>? users, |
|
|
|
super.baseURL, { |
|
|
|
final List<String>? apps, |
|
|
|
super.username, |
|
|
|
}) async { |
|
|
|
super.password, |
|
|
|
final hash = sha1 |
|
|
|
super.language, |
|
|
|
.convert( |
|
|
|
super.appType, |
|
|
|
utf8.encode( |
|
|
|
super.userAgentOverride, |
|
|
|
<String>[ |
|
|
|
}); |
|
|
|
if (users != null) |
|
|
|
} |
|
|
|
for (final user in users) user.toString(), |
|
|
|
|
|
|
|
if (apps != null) ...apps, |
|
|
|
|
|
|
|
].join(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.toString(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final dockerImageName = 'nextcloud-neon-$hash'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<TestNextcloudClient> getTestClient( |
|
|
|
|
|
|
|
final DockerContainer container, { |
|
|
|
|
|
|
|
final String? username = defaultUsername, |
|
|
|
|
|
|
|
final String? password = defaultPassword, |
|
|
|
|
|
|
|
final bool useAppPassword = false, |
|
|
|
|
|
|
|
final AppType appType = AppType.unknown, |
|
|
|
|
|
|
|
final String? userAgentOverride, |
|
|
|
|
|
|
|
}) async { |
|
|
|
|
|
|
|
// ignore: prefer_asserts_with_message |
|
|
|
|
|
|
|
assert(!useAppPassword || (username != null && password != null)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var clientPassword = password; |
|
|
|
|
|
|
|
if (useAppPassword) { |
|
|
|
final inputStream = StreamController<List<int>>(); |
|
|
|
final inputStream = StreamController<List<int>>(); |
|
|
|
final process = runExecutableArguments( |
|
|
|
final process = runExecutableArguments( |
|
|
|
'docker', |
|
|
|
'docker', |
|
|
|
[ |
|
|
|
[ |
|
|
|
'build', |
|
|
|
'exec', |
|
|
|
'-t', |
|
|
|
'-i', |
|
|
|
dockerImageName, |
|
|
|
container.id, |
|
|
|
|
|
|
|
'php', |
|
|
|
'-f', |
|
|
|
'-f', |
|
|
|
'-', |
|
|
|
'occ', |
|
|
|
'./test', |
|
|
|
'user:add-app-password', |
|
|
|
|
|
|
|
username!, |
|
|
|
], |
|
|
|
], |
|
|
|
stdout: stdout, |
|
|
|
|
|
|
|
stderr: stderr, |
|
|
|
|
|
|
|
stdin: inputStream.stream, |
|
|
|
stdin: inputStream.stream, |
|
|
|
); |
|
|
|
); |
|
|
|
inputStream.add( |
|
|
|
inputStream.add(utf8.encode(password!)); |
|
|
|
utf8.encode( |
|
|
|
|
|
|
|
TestDockerHelper.generateInstructions( |
|
|
|
|
|
|
|
nextcloudVersion, |
|
|
|
|
|
|
|
users: users, |
|
|
|
|
|
|
|
apps: apps, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
await inputStream.close(); |
|
|
|
await inputStream.close(); |
|
|
|
|
|
|
|
|
|
|
|
final result = await process; |
|
|
|
final result = await process; |
|
|
|
if (result.exitCode != 0) { |
|
|
|
if (result.exitCode != 0) { |
|
|
|
throw Exception('Failed to build docker image'); |
|
|
|
throw Exception('Failed to run generate app password command\n${result.stderr}\n${result.stdout}'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
clientPassword = (result.stdout as String).split('\n')[1]; |
|
|
|
return dockerImageName; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static Future<TestNextcloudClient> getPreparedClient( |
|
|
|
final client = TestNextcloudClient( |
|
|
|
final String dockerImageName, { |
|
|
|
'http://localhost:${container.port}', |
|
|
|
final String? username = defaultUsername, |
|
|
|
username: username, |
|
|
|
final String? password = defaultPassword, |
|
|
|
password: clientPassword, |
|
|
|
final bool useAppPassword = false, |
|
|
|
appType: appType, |
|
|
|
final AppType appType = AppType.unknown, |
|
|
|
userAgentOverride: userAgentOverride, |
|
|
|
final String? userAgentOverride, |
|
|
|
); |
|
|
|
}) async { |
|
|
|
|
|
|
|
// ignore: prefer_asserts_with_message |
|
|
|
while (true) { |
|
|
|
assert(!useAppPassword || (username != null && password != null)); |
|
|
|
// Test will timeout after 30s |
|
|
|
|
|
|
|
try { |
|
|
|
late ProcessResult result; |
|
|
|
await client.core.getStatus(); |
|
|
|
late int port; |
|
|
|
break; |
|
|
|
while (true) { |
|
|
|
} catch (_) { |
|
|
|
port = randomPort(); |
|
|
|
await Future.delayed(const Duration(milliseconds: 100)); |
|
|
|
result = await runExecutableArguments( |
|
|
|
|
|
|
|
'docker', |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'run', |
|
|
|
|
|
|
|
'--rm', |
|
|
|
|
|
|
|
'-d', |
|
|
|
|
|
|
|
'-p', |
|
|
|
|
|
|
|
'$port:80', |
|
|
|
|
|
|
|
'--add-host', |
|
|
|
|
|
|
|
'host.docker.internal:host-gateway', |
|
|
|
|
|
|
|
dockerImageName, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
// 125 means the docker run command itself has failed which indicated the port is already used |
|
|
|
|
|
|
|
if (result.exitCode != 125) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result.exitCode != 0) { |
|
|
|
|
|
|
|
throw Exception('Failed to run docker container: ${result.stderr}'); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final containerID = result.stdout.toString().replaceAll('\n', ''); |
|
|
|
return client; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var clientPassword = password; |
|
|
|
Future<DockerContainer> getDockerContainer(final DockerImage image) async { |
|
|
|
if (useAppPassword) { |
|
|
|
late ProcessResult result; |
|
|
|
final inputStream = StreamController<List<int>>(); |
|
|
|
late int port; |
|
|
|
final process = runExecutableArguments( |
|
|
|
while (true) { |
|
|
|
'docker', |
|
|
|
port = randomPort(); |
|
|
|
[ |
|
|
|
result = await runExecutableArguments( |
|
|
|
'exec', |
|
|
|
'docker', |
|
|
|
'-i', |
|
|
|
[ |
|
|
|
containerID, |
|
|
|
'run', |
|
|
|
'php', |
|
|
|
'--rm', |
|
|
|
'-f', |
|
|
|
'-d', |
|
|
|
'occ', |
|
|
|
'-p', |
|
|
|
'user:add-app-password', |
|
|
|
'$port:80', |
|
|
|
username!, |
|
|
|
'--add-host', |
|
|
|
], |
|
|
|
'host.docker.internal:host-gateway', |
|
|
|
stdin: inputStream.stream, |
|
|
|
image.name, |
|
|
|
); |
|
|
|
], |
|
|
|
inputStream.add(utf8.encode(password!)); |
|
|
|
); |
|
|
|
await inputStream.close(); |
|
|
|
// 125 means the docker run command itself has failed which indicated the port is already used |
|
|
|
|
|
|
|
if (result.exitCode != 125) { |
|
|
|
final result = await process; |
|
|
|
break; |
|
|
|
if (result.exitCode != 0) { |
|
|
|
|
|
|
|
throw Exception('Failed to run generate app password command\n${result.stderr}\n${result.stdout}'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
clientPassword = (result.stdout as String).split('\n')[1]; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
final client = TestNextcloudClient( |
|
|
|
if (result.exitCode != 0) { |
|
|
|
'http://localhost:$port', |
|
|
|
throw Exception('Failed to run docker container: ${result.stderr}'); |
|
|
|
containerID, |
|
|
|
} |
|
|
|
username: username, |
|
|
|
|
|
|
|
password: clientPassword, |
|
|
|
|
|
|
|
appType: appType, |
|
|
|
|
|
|
|
userAgentOverride: userAgentOverride, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (true) { |
|
|
|
return DockerContainer( |
|
|
|
// Test will timeout after 30s |
|
|
|
id: result.stdout.toString().replaceAll('\n', ''), |
|
|
|
try { |
|
|
|
port: port, |
|
|
|
await client.core.getStatus(); |
|
|
|
); |
|
|
|
break; |
|
|
|
} |
|
|
|
} catch (_) { |
|
|
|
|
|
|
|
await Future.delayed(const Duration(milliseconds: 100)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return client; |
|
|
|
Future<DockerImage> getDockerImage({ |
|
|
|
|
|
|
|
final List<TestNextcloudUser>? users, |
|
|
|
|
|
|
|
final List<String>? apps, |
|
|
|
|
|
|
|
}) async { |
|
|
|
|
|
|
|
final hash = sha1 |
|
|
|
|
|
|
|
.convert( |
|
|
|
|
|
|
|
utf8.encode( |
|
|
|
|
|
|
|
<String>[ |
|
|
|
|
|
|
|
if (users != null) |
|
|
|
|
|
|
|
for (final user in users) user.toString(), |
|
|
|
|
|
|
|
if (apps != null) ...apps, |
|
|
|
|
|
|
|
].join(), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.toString(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final dockerImageName = 'nextcloud-neon-$hash'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final inputStream = StreamController<List<int>>(); |
|
|
|
|
|
|
|
final process = runExecutableArguments( |
|
|
|
|
|
|
|
'docker', |
|
|
|
|
|
|
|
[ |
|
|
|
|
|
|
|
'build', |
|
|
|
|
|
|
|
'-t', |
|
|
|
|
|
|
|
dockerImageName, |
|
|
|
|
|
|
|
'-f', |
|
|
|
|
|
|
|
'-', |
|
|
|
|
|
|
|
'./test', |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
stdout: stdout, |
|
|
|
|
|
|
|
stderr: stderr, |
|
|
|
|
|
|
|
stdin: inputStream.stream, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
inputStream.add( |
|
|
|
|
|
|
|
utf8.encode( |
|
|
|
|
|
|
|
TestDockerHelper.generateInstructions( |
|
|
|
|
|
|
|
nextcloudVersion, |
|
|
|
|
|
|
|
users: users, |
|
|
|
|
|
|
|
apps: apps, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
await inputStream.close(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final result = await process; |
|
|
|
|
|
|
|
if (result.exitCode != 0) { |
|
|
|
|
|
|
|
throw Exception('Failed to build docker image'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DockerImage( |
|
|
|
|
|
|
|
name: dockerImageName, |
|
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class TestNextcloudUser { |
|
|
|
class TestNextcloudUser { |
|
|
|