Skip to content

Commit

Permalink
Sanitize uuid, timeonly and dateonly values to strings before passing…
Browse files Browse the repository at this point in the history
… them as substitutions
  • Loading branch information
ricardoboss committed Mar 20, 2024
1 parent f2606b0 commit 940872f
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/src/request_information.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ class RequestInformation {
return value.toIso8601String();
}

if (value is UuidValue) {
return value.toFormattedString();
}

if (value is TimeOnly) {
return value.toRfc3339String();
}

if (value is DateOnly) {
return value.toRfc3339String();
}

if (value is Enum) {
return value.name;
}
Expand Down
46 changes: 46 additions & 0 deletions test/request_information_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'dart:typed_data';
import 'package:kiota_abstractions/kiota_abstractions.dart';
import 'package:mockito/annotations.dart';
import 'package:test/test.dart';
import 'package:uuid/uuid.dart';

import 'request_information_test.mocks.dart';

Expand Down Expand Up @@ -92,6 +93,51 @@ void main() {
);
});

test('Sets path parameters of DateOnly type', () {
final requestInfo = RequestInformation(
httpMethod: HttpMethod.get,
urlTemplate: 'http://localhost/{date}',
);

// Act
final date = DateOnly.fromComponents(2024, 3, 20);
requestInfo.pathParameters['date'] = date;

// Assert
expect(requestInfo.uri.toString(), endsWith('2024-03-20'));
});

test('Sets path parameters of TimeOnly type', () {
final requestInfo = RequestInformation(
httpMethod: HttpMethod.get,
urlTemplate: 'http://localhost/{time}',
);

// Act
final time = TimeOnly.fromComponents(12, 34, 56);
requestInfo.pathParameters['time'] = time;

// Assert
expect(requestInfo.uri.toString(), endsWith('12%3A34%3A56'));
});

test('Sets path parameters of UuidValue type', () {
final requestInfo = RequestInformation(
httpMethod: HttpMethod.get,
urlTemplate: 'http://localhost/{uuid}',
);

// Act
final uuid = UuidValue.fromString('01234567-89ab-cdef-0123-456789abcdef');
requestInfo.pathParameters['uuid'] = uuid;

// Assert
expect(
requestInfo.uri.toString(),
endsWith('01234567-89ab-cdef-0123-456789abcdef'),
);
});

test('Sets path parameters of boolean type', () {
// Arrange as the request builders would
final requestInfo = RequestInformation(
Expand Down

0 comments on commit 940872f

Please sign in to comment.