blob: 93cbbd56dce09ee29bd464691969ffa1f76d1c4e [file] [log] [blame]
// Copyright 2019 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:auto_submit/request_handling/authentication.dart';
import 'package:auto_submit/requests/exceptions.dart';
import 'package:test/test.dart';
import 'package:shelf/shelf.dart';
void main() {
group('CronAuthProvider', () {
late Request request;
late CronAuthProvider auth;
setUp(() {
auth = const CronAuthProvider();
});
test('throws Unauthenticated with no auth headers', () async {
request = Request('POST', Uri.parse('http://localhost/'));
expect(auth.authenticate(request), throwsA(isA<Unauthenticated>()));
});
test('succeeds for App Engine cronjobs', () async {
final Map<String, String> header = {'X-Appengine-Cron': 'true'};
request = Request('POST', Uri.parse('http://localhost/'), headers: header);
final bool result = await auth.authenticate(request);
expect(result, true);
});
});
}