-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fixed error with anonymous authentication (Fixes #779) * Add license headers
- Loading branch information
1 parent
6e8059f
commit 4633709
Showing
6 changed files
with
144 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'] | ||
} | ||
|
66 changes: 66 additions & 0 deletions
66
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,66 @@ | ||
/* | ||
* Copyright (C)2016 - SMBJ Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
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,36 @@ | ||
/* | ||
* Copyright (C)2016 - SMBJ Contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
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