22using ImapMethods = RuriLib . Blocks . Requests . Imap . Methods ;
33using Pop3Methods = RuriLib . Blocks . Requests . Pop3 . Methods ;
44using RuriLib . Exceptions ;
5+ using RuriLib . Functions . Imap ;
6+ using RuriLib . Functions . Pop3 ;
7+ using RuriLib . Functions . Smtp ;
58using RuriLib . Logging ;
69using RuriLib . Models . Bots ;
710using RuriLib . Models . Configs ;
811using RuriLib . Models . Data ;
912using RuriLib . Models . Environment ;
13+ using RuriLib . Providers . Emails ;
1014using SmtpMethods = RuriLib . Blocks . Requests . Smtp . Methods ;
1115using RuriLib . Tests . Utils . Mockup ;
1216using System . Collections . Generic ;
@@ -123,6 +127,45 @@ public async Task SmtpSendMailAdvanced_WithoutClient_Throws()
123127 Assert . Equal ( "Connect the SMTP client first!" , ex . Message ) ;
124128 }
125129
130+ [ Fact ]
131+ public async Task SmtpAutoConnect_KnownServersOnly_DoesNotFallback ( )
132+ {
133+ var repository = new InMemoryEmailDomainRepository ( ) ;
134+ repository . AddSmtp ( "test.local" , "127.0.0.1" , 1 ) ;
135+ var data = NewBotData ( repository ) ;
136+
137+ var ex = await Assert . ThrowsAsync < BlockExecutionException > ( ( ) =>
138+ SmtpMethods . SmtpAutoConnect ( data , "test1@test.local" , 250 , SmtpAutoConnectMode . KnownServersOnly ) ) ;
139+
140+ Assert . Equal ( "Exhausted the known SMTP servers from smtpdomains.dat, failed to connect!" , ex . Message ) ;
141+ }
142+
143+ [ Fact ]
144+ public async Task ImapAutoConnect_KnownServersOnly_DoesNotFallback ( )
145+ {
146+ var repository = new InMemoryEmailDomainRepository ( ) ;
147+ repository . AddImap ( "test.local" , "127.0.0.1" , 1 ) ;
148+ var data = NewBotData ( repository ) ;
149+
150+ var ex = await Assert . ThrowsAsync < BlockExecutionException > ( ( ) =>
151+ ImapMethods . ImapAutoConnect ( data , "test1@test.local" , 250 , ImapAutoConnectMode . KnownServersOnly ) ) ;
152+
153+ Assert . Equal ( "Exhausted the known IMAP servers from imapdomains.dat, failed to connect!" , ex . Message ) ;
154+ }
155+
156+ [ Fact ]
157+ public async Task Pop3AutoConnect_KnownServersOnly_DoesNotFallback ( )
158+ {
159+ var repository = new InMemoryEmailDomainRepository ( ) ;
160+ repository . AddPop3 ( "test.local" , "127.0.0.1" , 1 ) ;
161+ var data = NewBotData ( repository ) ;
162+
163+ var ex = await Assert . ThrowsAsync < BlockExecutionException > ( ( ) =>
164+ Pop3Methods . Pop3AutoConnect ( data , "test1@test.local" , 250 , Pop3AutoConnectMode . KnownServersOnly ) ) ;
165+
166+ Assert . Equal ( "Exhausted the known POP3 servers from pop3domains.dat, failed to connect!" , ex . Message ) ;
167+ }
168+
126169 private static ProtocolLogger CreateLogger ( string content )
127170 {
128171 var stream = new MemoryStream ( Encoding . UTF8 . GetBytes ( content ) )
@@ -132,10 +175,11 @@ private static ProtocolLogger CreateLogger(string content)
132175 return new ProtocolLogger ( stream ) ;
133176 }
134177
135- private static BotData NewBotData ( )
178+ private static BotData NewBotData ( IEmailDomainRepository ? emailDomains = null )
136179 => new (
137180 new BotProviders ( null ! )
138181 {
182+ EmailDomains = emailDomains ?? new InMemoryEmailDomainRepository ( ) ,
139183 ProxySettings = new MockedProxySettingsProvider ( ) ,
140184 Security = new MockedSecurityProvider ( )
141185 } ,
0 commit comments