-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed error with anonymous authentication (Fixes #779)
- Loading branch information
1 parent
6e8059f
commit 32d2ba0
Showing
6 changed files
with
114 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,9 @@ testing { | |
} | ||
|
||
sources { | ||
java { | ||
srcDirs = ['src/it/java'] | ||
} | ||
groovy { | ||
srcDirs = ['src/it/groovy'] | ||
} | ||
|
51 changes: 51 additions & 0 deletions
51
src/it/java/com/hierynomus/smbj/AnonymousIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.hierynomus.smbj; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.hierynomus.mssmb2.SMB2Dialect; | ||
import com.hierynomus.security.bc.BCSecurityProvider; | ||
import com.hierynomus.smbj.auth.AuthenticationContext; | ||
import com.hierynomus.smbj.session.SMB2GuestSigningRequiredException; | ||
import com.hierynomus.smbj.session.Session; | ||
import com.hierynomus.smbj.share.DiskShare; | ||
import com.hierynomus.smbj.share.Share; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static com.hierynomus.smbj.testing.TestingUtils.*; | ||
|
||
public class AnonymousIntegrationTest { | ||
|
||
private SmbConfig base = SmbConfig.builder().withDialects(SMB2Dialect.SMB_3_1_1).withEncryptData(true).withSigningRequired(false).withMultiProtocolNegotiate(true).withDfsEnabled(true).withSecurityProvider(new BCSecurityProvider()).build(); | ||
|
||
@Test | ||
public void shouldAuthenticateAnonymous() throws Exception { | ||
withConnectedClient(base, (connection) -> { | ||
try (Session session = connection.authenticate(AuthenticationContext.anonymous())) { | ||
assertNotNull(session.getSessionId()); | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void shouldFailConnectingAnonymousWhenSigningRequired() throws Exception { | ||
SmbConfig config = SmbConfig.builder(base).withSigningRequired(true).build(); | ||
assertThrows(SMB2GuestSigningRequiredException.class, () -> withConnectedClient(config, (connection) -> { | ||
try (Session session = connection.authenticate(AuthenticationContext.anonymous())) { | ||
fail("Should not be able to connect"); | ||
} | ||
})); | ||
} | ||
|
||
@Test | ||
public void shouldConnectToPublicShare() throws Exception { | ||
withConnectedClient(base, (connection) -> { | ||
try (Session session = connection.authenticate(AuthenticationContext.anonymous())) { | ||
try (Share share = session.connectShare("public")) { | ||
assertInstanceOf(DiskShare.class, share); | ||
assertTrue(share.isConnected()); | ||
assertNotNull(share.getTreeConnect().getTreeId()); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.hierynomus.smbj.testing; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import com.hierynomus.smbj.SMBClient; | ||
import com.hierynomus.smbj.SmbConfig; | ||
import com.hierynomus.smbj.connection.Connection; | ||
|
||
public class TestingUtils { | ||
public static void withConnectedClient(SmbConfig config, ConsumerWithError<Connection> f) throws Exception { | ||
try (SMBClient client = new SMBClient(config)) { | ||
try (Connection connection = client.connect("127.0.0.1")) { | ||
f.accept(connection); | ||
} | ||
} | ||
} | ||
|
||
public interface ConsumerWithError<T> { | ||
void accept(T val) throws Exception; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters