1+ using Genbox . SimpleS3 . Core . Abstracts ;
2+ using Genbox . SimpleS3 . Core . Abstracts . Enums ;
3+ using Genbox . SimpleS3 . Core . Abstracts . Provider ;
4+ using Genbox . SimpleS3 . Core . Abstracts . Request ;
5+ using Genbox . SimpleS3 . Core . Common . Authentication ;
6+ using Genbox . SimpleS3 . Core . Common . Validation ;
7+ using Genbox . SimpleS3 . Core . Extensions ;
8+ using Genbox . SimpleS3 . Core . TestBase . Code ;
9+ using Genbox . SimpleS3 . Extensions . GenericS3 . Extensions ;
10+ using Microsoft . Extensions . DependencyInjection ;
11+ using Microsoft . Extensions . Options ;
12+
13+ namespace Genbox . SimpleS3 . Core . Tests . GenericTests ;
14+
15+ public class ValidationTests
16+ {
17+ [ Fact ]
18+ public void EnsureValidationIsRun ( )
19+ {
20+ ServiceCollection services = new ServiceCollection ( ) ;
21+ services . AddSingleton < INetworkDriver , NullNetworkDriver > ( ) ;
22+ services . AddSingleton < IInputValidator , LocalValidator > ( ) ;
23+
24+ ICoreBuilder builder = SimpleS3CoreServices . AddSimpleS3Core ( services ) ;
25+
26+ builder . UseGenericS3 ( config =>
27+ {
28+ config . Endpoint = "https://localhost" ;
29+ config . RegionCode = "us-west-2" ;
30+ config . NamingMode = NamingMode . PathStyle ;
31+ config . Credentials = new StringAccessKey ( "test" , "secret" ) ;
32+ } ) ;
33+
34+ IServiceProvider serviceProvider = services . BuildServiceProvider ( ) ;
35+
36+ OptionsValidationException ex = Assert . Throws < OptionsValidationException > ( ( ) => serviceProvider . GetRequiredService < ISimpleClient > ( ) ) ;
37+ Assert . Equal ( "Invalid key id: The input was not the correct length. Length should be '20'" , ex . Message ) ;
38+ }
39+
40+ private sealed class LocalValidator : InputValidatorBase
41+ {
42+ protected override bool TryValidateKeyIdInternal ( string keyId , out ValidationStatus status , out string ? message )
43+ {
44+ if ( keyId . Length != 20 )
45+ {
46+ status = ValidationStatus . WrongLength ;
47+ message = "20" ;
48+ return false ;
49+ }
50+
51+ status = ValidationStatus . Ok ;
52+ message = null ;
53+ return true ;
54+ }
55+
56+ protected override bool TryValidateAccessKeyInternal ( byte [ ] accessKey , out ValidationStatus status , out string ? message )
57+ {
58+ status = ValidationStatus . Ok ;
59+ message = null ;
60+ return true ;
61+ }
62+
63+ protected override bool TryValidateBucketNameInternal ( string bucketName , BucketNameValidationMode mode , out ValidationStatus status , out string ? message )
64+ {
65+ status = ValidationStatus . Ok ;
66+ message = null ;
67+ return true ;
68+ }
69+
70+ protected override bool TryValidateObjectKeyInternal ( string objectKey , ObjectKeyValidationMode mode , out ValidationStatus status , out string ? message )
71+ {
72+ status = ValidationStatus . Ok ;
73+ message = null ;
74+ return true ;
75+ }
76+ }
77+ }
0 commit comments