Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(neon_framework): rename credentials password to appPassowrd #2488

Merged
merged 2 commits into from
Sep 15, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class _PushNotificationsBloc extends Bloc implements PushNotificationsBloc {

Future<void> registerUnifiedPushInstances(({Account? active, BuiltList<Account> accounts}) event) async {
// Notifications will only work on accounts with app password
for (final account in event.accounts.where((a) => a.password != null)) {
for (final account in event.accounts.where((a) => a.credentials.appPassword != null)) {
await UnifiedPush.registerApp(account.id);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/neon_framework/lib/src/testing/mock_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Account mockServer(
credentials: createCredentials(
serverURL: Uri.parse('https://example.com'),
username: 'test',
password: 'test',
appPassword: 'test',
),
httpClient: client,
);
Expand Down
4 changes: 2 additions & 2 deletions packages/neon_framework/lib/src/testing/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface.
Account MockAccount({
String serverURL = 'https://cloud.example.com:8443/nextcloud',
String username = 'username',
String password = 'password',
String appPassword = 'appPassword',
}) {
return createAccount(
credentials: createCredentials(
serverURL: Uri.parse(serverURL),
username: username,
password: password,
appPassword: appPassword,
),
httpClient: MockClient((_) async {
throw ClientException('The fake account client can not be used in tests.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ extension AccountClientExtension on Account {
/// In that case an instance hosted at a sub folder will already contain the sub folder part in the [uri].
@internal
Uri completeUri(Uri uri) {
final result = serverURL.resolveUri(uri);
final result = credentials.serverURL.resolveUri(uri);
if (!uri.hasAbsolutePath) {
return result.replace(path: '${serverURL.path}/${uri.path}');
return result.replace(path: '${credentials.serverURL.path}/${uri.path}');
}
return result;
}
Expand All @@ -23,7 +23,7 @@ extension AccountClientExtension on Account {
///
/// This method ensures no credentials are sent to the wrong server.
Map<String, String>? getAuthorizationHeaders(Uri uri) {
if (uri.toString().startsWith(serverURL.toString())) {
if (uri.toString().startsWith(credentials.serverURL.toString())) {
return client.authentications?.firstOrNull?.headers;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/neon_framework/lib/src/widgets/error.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class NeonError extends StatelessWidget {

static Future<void> _openLoginPage(BuildContext context) async {
await LoginRoute(
serverUrl: NeonProvider.of<Account>(context).serverURL,
serverUrl: NeonProvider.of<Account>(context).credentials.serverURL,
).push<void>(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class AccountRepository {
b
..serverURL = Uri.parse(response.server)
..username = response.loginName
..password = response.appPassword;
..appPassword = response.appPassword;
});
} on http.ClientException catch (error, stackTrace) {
if (error case DynamiteStatusCodeException(statusCode: 404)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@ abstract class Account implements Built<Account, AccountBuilder> {
/// The login and server credentials of the account.
Credentials get credentials;

/// Url of the server.
Uri get serverURL => credentials.serverURL;

/// The user id.
String get username => credentials.username;

/// App password.
String? get password => credentials.password;

/// The unique ID of the account.
///
/// Implemented in a primitive way hashing the [username] and [serverURL].
/// Implemented in a primitive way hashing the [username] and `serverURL`.
String get id => credentials.id;

/// A human readable representation of [username] and [serverURL].
/// A human readable representation of [username] and `serverURL`.
String get humanReadableID => credentials.humanReadableID;

/// An authenticated API client.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class Credentials implements Built<Credentials, CredentialsBuilder> {
String get username;

/// App password.
String? get password;
String? get appPassword;

/// The unique ID of the account.
///
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final class LoginQRcode with EquatableMixin {
b
..serverURL = Uri.parse(match.group(3)!)
..username = match.group(1)
..password = match.group(2);
..appPassword = match.group(2);
}),
);
}
Expand Down Expand Up @@ -91,7 +91,7 @@ final class LoginQRcode with EquatableMixin {
@override
String toString() {
final username = credentials.username;
final password = credentials.password;
final password = credentials.appPassword;
final serverURL = credentials.serverURL;

return 'nc://login/user:$username&password:$password&server:$serverURL';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import 'package:meta/meta.dart';
Credentials createCredentials({
Uri? serverURL,
String username = 'username',
String? password = 'password',
String? appPassword = 'appPassword',
}) {
return Credentials((b) {
b
..serverURL = serverURL ?? Uri.https('serverURL')
..username = username
..password = password;
..appPassword = appPassword;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ NextcloudClient buildClient({
return NextcloudClient(
credentials.serverURL,
loginName: credentials.username,
password: credentials.password,
appPassword: credentials.password,
password: credentials.appPassword,
appPassword: credentials.appPassword,
httpClient: neonHttpClient,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ void main() {
b
..serverURL = Uri.https('serverUrl')
..username = 'username'
..password = 'password';
..appPassword = 'appPassword';
}),
Credentials((b) {
b
..serverURL = Uri.https('other-serverUrl')
..username = 'username'
..password = 'password';
..appPassword = 'appPassword';
}),
]);

Expand Down Expand Up @@ -376,7 +376,7 @@ void main() {
equalsBuilt(
Credentials((b) {
b
..password = 'appPassword'
..appPassword = 'appPassword'
..username = 'loginName'
..serverURL = Uri.https('server');
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ void main() {
b
..serverURL = Uri.https('serverUrl')
..username = 'username'
..password = 'password';
..appPassword = 'appPassword';
}),
Credentials((b) {
b
..serverURL = Uri.https('other-serverUrl')
..username = 'username'
..password = 'password';
..appPassword = 'appPassword';
}),
];

final serializedCredentials = BuiltList<String>([
'{"serverURL":"https://serverurl","username":"username","password":"password"}',
'{"serverURL":"https://other-serverurl","username":"username","password":"password"}',
'{"serverURL":"https://serverurl","username":"username","appPassword":"appPassword"}',
'{"serverURL":"https://other-serverurl","username":"username","appPassword":"appPassword"}',
]);

group('AccountStorage', () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void main() {
isNot(
equals(
createAccount(
credentials: createCredentials(password: null),
credentials: createCredentials(appPassword: null),
),
),
),
Expand All @@ -49,14 +49,14 @@ void main() {
b.credentials
..serverURL = Uri.https('new-serverURL')
..username = 'new-username'
..password = 'new-password';
..appPassword = 'new-appPassword';
}),
equals(
createAccount(
credentials: createCredentials(
serverURL: Uri.https('new-serverURL'),
username: 'new-username',
password: 'new-password',
appPassword: 'new-appPassword',
),
),
),
Expand All @@ -69,9 +69,7 @@ void main() {
credentials: createCredentials(serverURL: Uri(host: 'server')),
);

expect(account.serverURL, equals(Uri(host: 'server')));
expect(account.username, equals('username'));
expect(account.password, equals('password'));
expect(account.id, equals('43c2c7ec8332735e75756dcb08c4fcc6c2b07071'));
expect(account.humanReadableID, equals('username@server'));
});
Expand All @@ -84,7 +82,7 @@ Account {
credentials=Credentials {
serverURL=https://serverurl,
username=username,
password=password,
appPassword=appPassword,
},
client=Instance of 'NextcloudClient',
}'''),
Expand Down
Loading