Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Nov 21, 2024
1 parent 92ac10d commit 9a9961c
Show file tree
Hide file tree
Showing 21 changed files with 820 additions and 437 deletions.
11 changes: 4 additions & 7 deletions lib/api/impl/privacy_idea_container_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class PiContainerApi implements TokenContainerApi {
CONTAINER_CHAL_SIGNATURE: container.signMessage(signMessage),
};

final response = await _ioClient.doPost(url: requestUrl, body: body);
final response = await _ioClient.doPost(url: requestUrl, body: body, sslVerify: container.sslVerify);
if (response.statusCode != 200) {
final errorResponse = response.asPiErrorResponse();
if (errorResponse != null) throw errorResponse.piServerResultError;
Expand Down Expand Up @@ -209,7 +209,7 @@ class PiContainerApi implements TokenContainerApi {
CONTAINER_CHAL_SIGNATURE: container.signMessage('${challenge.nonce}|${challenge.timeStamp}|${container.serial}|$unregisterUrl'),
};

final response = await _ioClient.doPost(url: unregisterUrl, body: body);
final response = await _ioClient.doPost(url: unregisterUrl, body: body, sslVerify: container.sslVerify);

final piResponse = response.asPiServerResponse<UnregisterContainerResultValue>();
final errorResponse = piResponse?.asError;
Expand All @@ -227,10 +227,7 @@ class PiContainerApi implements TokenContainerApi {
final body = {
CONTAINER_SCOPE: requestUrl.toString(),
};
final challengeResponse = await _ioClient.doPost(
url: container.challengeUrl,
body: body,
);
final challengeResponse = await _ioClient.doPost(url: container.challengeUrl, body: body, sslVerify: container.sslVerify);
if (challengeResponse.statusCode != 200) {
final errorResponse = challengeResponse.asPiErrorResponse();
if (errorResponse != null) throw errorResponse.piServerResultError;
Expand Down Expand Up @@ -270,7 +267,7 @@ class PiContainerApi implements TokenContainerApi {
CONTAINER_CHAL_SIGNATURE: signature,
};

final response = await _ioClient.doPost(url: container.syncUrl, body: body);
final response = await _ioClient.doPost(url: container.syncUrl, body: body, sslVerify: container.sslVerify);
if (response.statusCode != 200) {
final piErrorResponse = response.asPiErrorResponse();
if (piErrorResponse != null) throw piErrorResponse.piServerResultError;
Expand Down
1 change: 0 additions & 1 deletion lib/interfaces/repo/token_container_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import '../../model/token_container.dart';
abstract class TokenContainerRepository {
Future<TokenContainerState> loadContainerState();
Future<TokenContainerState> saveContainerState(TokenContainerState containerState);
Future<List<TokenContainer>> loadContainerList();
Future<TokenContainerState> saveContainerList(List<TokenContainer> containerList);
Future<TokenContainerState> deleteContainer(String serial);
Future<TokenContainerState> deleteAllContainer();
Expand Down
8 changes: 6 additions & 2 deletions lib/model/pi_server_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class PiServerResponse<T extends PiServerResultValue> with _$PiServerResponse {

const PiServerResponse._();
factory PiServerResponse.success({
required int statusCode,
required dynamic detail,
required int id,
required String jsonrpc,
Expand All @@ -61,6 +62,7 @@ class PiServerResponse<T extends PiServerResultValue> with _$PiServerResponse {
PiSuccessResponse<T>? get asSuccess => this is PiSuccessResponse<T> ? this as PiSuccessResponse<T> : null;

factory PiServerResponse.error({
required int statusCode,
required dynamic detail,
required int id,
required String jsonrpc,
Expand All @@ -75,7 +77,7 @@ class PiServerResponse<T extends PiServerResultValue> with _$PiServerResponse {
bool get isError => this is PiErrorResponse;
PiErrorResponse<T>? get asError => this is PiErrorResponse<T> ? this as PiErrorResponse<T> : null;

factory PiServerResponse.fromJson(Map<String, dynamic> json) {
factory PiServerResponse.fromJson(Map<String, dynamic> json, {int statisCode = 200}) {
Logger.debug('Received container sync response: $json');
final map = validateMap<dynamic>(
map: json,
Expand All @@ -102,6 +104,7 @@ class PiServerResponse<T extends PiServerResultValue> with _$PiServerResponse {
);
if (result[RESULT_STATUS] == true && result.containsKey(RESULT_VALUE)) {
return PiServerResponse.success(
statusCode: statisCode,
id: map[ID],
jsonrpc: map[JSONRPC],
resultValue: PiServerResultValue.fromJsonOfType<T>(result[RESULT_VALUE]),
Expand All @@ -114,6 +117,7 @@ class PiServerResponse<T extends PiServerResultValue> with _$PiServerResponse {
}
if (result[RESULT_STATUS] == false && result.containsKey(RESULT_ERROR)) {
return PiServerResponse.error(
statusCode: statisCode,
detail: map[DETAIL],
id: json[ID],
jsonrpc: map[JSONRPC],
Expand All @@ -132,6 +136,6 @@ class PiServerResponse<T extends PiServerResultValue> with _$PiServerResponse {
}

factory PiServerResponse.fromResponse(Response response) {
return PiServerResponse<T>.fromJson(jsonDecode(response.body));
return PiServerResponse<T>.fromJson(jsonDecode(response.body), statisCode: response.statusCode);
}
}
Loading

0 comments on commit 9a9961c

Please sign in to comment.