From 451b439ecaf425688e11d278ec66edbd4207fa58 Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Wed, 13 Apr 2022 13:24:53 +0300 Subject: [PATCH] test: disable repository owner verification for tests --- lib/src/bindings/libgit2_bindings.dart | 25 +++++++++++++++++++++++-- lib/src/libgit2.dart | 22 ++++++++++++++++++++++ test/helpers/util.dart | 2 ++ test/libgit2_test.dart | 10 ++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/lib/src/bindings/libgit2_bindings.dart b/lib/src/bindings/libgit2_bindings.dart index a65a271..905a535 100644 --- a/lib/src/bindings/libgit2_bindings.dart +++ b/lib/src/bindings/libgit2_bindings.dart @@ -2480,17 +2480,38 @@ class Libgit2 { /// @return 0 on success, <0 on failure int git_libgit2_opts( int option, + ffi.Pointer out, ) { return _git_libgit2_opts( option, + out, ); } late final _git_libgit2_optsPtr = - _lookup>( + _lookup)>>( 'git_libgit2_opts'); late final _git_libgit2_opts = - _git_libgit2_optsPtr.asFunction(); + _git_libgit2_optsPtr.asFunction)>(); + + /// Set a library global option. + /// + /// Look at [git_libgit2_opts] + int git_libgit2_opts_set( + int option, + int value, + ) { + return _git_libgit2_opts_set( + option, + value, + ); + } + + late final _git_libgit2_opts_setPtr = + _lookup>( + 'git_libgit2_opts'); + late final _git_libgit2_opts_set = + _git_libgit2_opts_setPtr.asFunction(); /// Free the memory referred to by the git_buf. /// diff --git a/lib/src/libgit2.dart b/lib/src/libgit2.dart index f935d42..cbd611b 100644 --- a/lib/src/libgit2.dart +++ b/lib/src/libgit2.dart @@ -2,6 +2,7 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:libgit2dart/libgit2dart.dart'; +import 'package:libgit2dart/src/bindings/libgit2_bindings.dart'; import 'package:libgit2dart/src/util.dart'; class Libgit2 { @@ -33,4 +34,25 @@ class Libgit2 { .where((e) => featuresInt & e.value == e.value) .toSet(); } + + /// Returns owner validation setting for repository directories. + static bool get ownerValidation { + libgit2.git_libgit2_init(); + final out = calloc(); + libgit2.git_libgit2_opts( + git_libgit2_opt_t.GIT_OPT_GET_OWNER_VALIDATION, + out, + ); + return out.value == 1 || false; + } + + /// Sets owner validation setting for repository directories. + static set ownerValidation(bool value) { + libgit2.git_libgit2_init(); + final valueC = value ? 1 : 0; + libgit2.git_libgit2_opts_set( + git_libgit2_opt_t.GIT_OPT_SET_OWNER_VALIDATION, + valueC, + ); + } } diff --git a/test/helpers/util.dart b/test/helpers/util.dart index bfdb505..17d4066 100644 --- a/test/helpers/util.dart +++ b/test/helpers/util.dart @@ -1,7 +1,9 @@ import 'dart:io'; +import 'package:libgit2dart/libgit2dart.dart'; import 'package:path/path.dart' as p; Directory setupRepo(Directory repoDir) { + Libgit2.ownerValidation = false; final tmpDir = Directory.systemTemp.createTempSync('testrepo'); copyRepo(from: repoDir, to: tmpDir); return tmpDir; diff --git a/test/libgit2_test.dart b/test/libgit2_test.dart index 6896649..fdc8bfe 100644 --- a/test/libgit2_test.dart +++ b/test/libgit2_test.dart @@ -14,5 +14,15 @@ void main() { {GitFeature.threads, GitFeature.https, GitFeature.ssh, GitFeature.nsec}, ); }); + + test('returns the owner validation setting for repository directories', () { + expect(Libgit2.ownerValidation, true); + }); + + test('sets the owner validation setting for repository directories', () { + expect(Libgit2.ownerValidation, true); + Libgit2.ownerValidation = false; + expect(Libgit2.ownerValidation, false); + }); }); }