feat(train): the instance names its map source (ADR 0030, D11, D22)
Train's first endpoint of its own, map.source, names the map workouts are drawn on, for people signed in only, as a provider's key may be in its style's address: OpenFreeMap's Liberty style where the operator sets nothing, else MAP_STYLE_URL (HTTPS only) with MAP_SOURCE_NAME, MAP_ATTRIBUTION and MAP_ABOUT_URL. A model without a table: no migration. D22 is recorded in ADR 0030. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
7df1cb1740
commit
dd778cb2cd
3 changed files with 574 additions and 4 deletions
|
|
@ -0,0 +1,36 @@
|
|||
import 'package:serverpod/serverpod.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../test_tools/serverpod_test_tools.dart';
|
||||
|
||||
/// The map the app draws workouts on, as the instance names it (ADR 0030,
|
||||
/// D11, D22): for the people signed in, as the provider's key may be in it.
|
||||
void main() {
|
||||
withServerpod('The map source', (sessionBuilder, endpoints) {
|
||||
test('names OpenFreeMap to someone signed in, where the operator sets '
|
||||
'nothing', () async {
|
||||
final source = await endpoints.map.source(
|
||||
sessionBuilder.copyWith(
|
||||
authentication: AuthenticationOverride.authenticationInfo(
|
||||
const Uuid().v7(),
|
||||
{},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(source.name, 'OpenFreeMap');
|
||||
expect(source.styleUrl, startsWith('https://tiles.openfreemap.org/'));
|
||||
});
|
||||
|
||||
test('names nothing to nobody signed in', () async {
|
||||
await expectLater(
|
||||
endpoints.map.source(
|
||||
sessionBuilder.copyWith(
|
||||
authentication: AuthenticationOverride.unauthenticated(),
|
||||
),
|
||||
),
|
||||
throwsA(isA<ServerpodUnauthenticatedException>()),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -11,9 +11,12 @@
|
|||
// ignore_for_file: no_leading_underscores_for_local_identifiers
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _ida;
|
||||
import 'dart:io' as _idi;
|
||||
import 'package:halkyon_train_server/src/generated/future_calls.dart'
|
||||
as _i59xasdy;
|
||||
import 'package:halkyon_train_server/src/generated/map/map_source.dart'
|
||||
as _ip8bmyd2;
|
||||
import 'package:serverpod/serverpod.dart' as _is;
|
||||
import 'package:serverpod_test/serverpod_test.dart' as _ist;
|
||||
import 'package:halkyon_train_server/src/generated/protocol.dart';
|
||||
|
|
@ -150,6 +153,8 @@ void withServerpod(
|
|||
|
||||
class TestEndpoints {
|
||||
late final futureCalls = _FutureCalls();
|
||||
|
||||
late final _MapEndpoint map;
|
||||
}
|
||||
|
||||
class _InternalTestEndpoints extends TestEndpoints
|
||||
|
|
@ -158,13 +163,59 @@ class _InternalTestEndpoints extends TestEndpoints
|
|||
void initialize(
|
||||
_is.SerializationManager serializationManager,
|
||||
_is.EndpointDispatch endpoints,
|
||||
) {}
|
||||
) {
|
||||
map = _MapEndpoint(
|
||||
endpoints,
|
||||
serializationManager,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FutureCalls {
|
||||
late final pruning = _PruningFutureCall();
|
||||
}
|
||||
|
||||
class _MapEndpoint {
|
||||
_MapEndpoint(
|
||||
this._endpointDispatch,
|
||||
this._serializationManager,
|
||||
);
|
||||
|
||||
final _is.EndpointDispatch _endpointDispatch;
|
||||
|
||||
final _is.SerializationManager _serializationManager;
|
||||
|
||||
_ida.Future<_ip8bmyd2.MapSource> source(
|
||||
_ist.TestSessionBuilder sessionBuilder,
|
||||
) async {
|
||||
return _ist.callAwaitableFunctionAndHandleExceptions(() async {
|
||||
var _localUniqueSession =
|
||||
(sessionBuilder as _ist.InternalTestSessionBuilder).internalBuild(
|
||||
endpoint: 'map',
|
||||
method: 'source',
|
||||
);
|
||||
try {
|
||||
var _localCallContext = await _endpointDispatch.getMethodCallContext(
|
||||
createSessionCallback: (_) => _localUniqueSession,
|
||||
endpointPath: 'map',
|
||||
methodName: 'source',
|
||||
parameters: _ist.testObjectToJson({}),
|
||||
serializationManager: _serializationManager,
|
||||
);
|
||||
var _localReturnValue =
|
||||
await (_localCallContext.method.call(
|
||||
_localUniqueSession,
|
||||
_localCallContext.arguments,
|
||||
)
|
||||
as _ida.Future<_ip8bmyd2.MapSource>);
|
||||
return _localReturnValue;
|
||||
} finally {
|
||||
await _localUniqueSession.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class _PruningFutureCall {
|
||||
Future<void> pruneAccounts(_ist.TestSessionBuilder sessionBuilder) async {
|
||||
var _localUniqueSession =
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
import 'package:halkyon_train_server/src/map/map_source_config.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
/// The instance's map source as its operator sets it (ADR 0030, D11, D22).
|
||||
void main() {
|
||||
test('without a setting it is OpenFreeMap, named, with its attribution', () {
|
||||
final source = mapSourceFrom(const {});
|
||||
|
||||
expect(source.name, 'OpenFreeMap');
|
||||
expect(source.styleUrl, 'https://tiles.openfreemap.org/styles/liberty');
|
||||
expect(source.attribution, contains('OpenStreetMap'));
|
||||
expect(source.aboutUrl, 'https://openfreemap.org');
|
||||
});
|
||||
|
||||
test("an operator's provider is named as they set it", () {
|
||||
final source = mapSourceFrom(const {
|
||||
'MAP_STYLE_URL':
|
||||
'https://api.maptiler.com/maps/outdoor-v2/style.json?key=k',
|
||||
'MAP_SOURCE_NAME': 'MapTiler',
|
||||
'MAP_ATTRIBUTION': '© MapTiler © OpenStreetMap contributors',
|
||||
'MAP_ABOUT_URL': 'https://www.maptiler.com/privacy-policy/',
|
||||
});
|
||||
|
||||
expect(source.name, 'MapTiler');
|
||||
expect(
|
||||
source.styleUrl,
|
||||
'https://api.maptiler.com/maps/outdoor-v2/style.json?key=k',
|
||||
);
|
||||
expect(source.attribution, '© MapTiler © OpenStreetMap contributors');
|
||||
expect(source.aboutUrl, 'https://www.maptiler.com/privacy-policy/');
|
||||
});
|
||||
|
||||
test('a provider without a name is named by its host, and credits '
|
||||
'OpenStreetMap', () {
|
||||
final source = mapSourceFrom(const {
|
||||
'MAP_STYLE_URL': 'https://maps.example.org/style.json',
|
||||
});
|
||||
|
||||
expect(source.name, 'maps.example.org');
|
||||
expect(source.attribution, '© OpenStreetMap contributors');
|
||||
expect(source.aboutUrl, isNull);
|
||||
});
|
||||
|
||||
test("a style that isn't HTTPS, or isn't an address, is never used: the "
|
||||
'map stays OpenFreeMap', () {
|
||||
for (final url in [
|
||||
'http://maps.example.org/style.json',
|
||||
'maps.example.org/style.json',
|
||||
'https://',
|
||||
' ',
|
||||
]) {
|
||||
expect(
|
||||
mapSourceFrom({'MAP_STYLE_URL': url}).name,
|
||||
'OpenFreeMap',
|
||||
reason: url,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("an about page that isn't HTTPS is left out", () {
|
||||
final source = mapSourceFrom(const {
|
||||
'MAP_STYLE_URL': 'https://maps.example.org/style.json',
|
||||
'MAP_ABOUT_URL': 'javascript:alert(1)',
|
||||
});
|
||||
|
||||
expect(source.aboutUrl, isNull);
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue