Skip to content
This repository was archived by the owner on Dec 4, 2023. It is now read-only.
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
31eef7d
Move InvokeResponse and TypedInvokeResponse to bot-schema
Batta32 Jul 14, 2021
0f8a03a
Relocate BotFrameworkClient to bot-connector
Batta32 Jul 14, 2021
f4ad8ab
Add Skill handle of CloudAdapter
Batta32 Jul 14, 2021
99b6908
Add Authentication configuration for CloudAdapter
Batta32 Jul 14, 2021
fe8cd7c
Add main classes of CloudAdapter and CloudAdapterBase
Batta32 Jul 14, 2021
9df6bef
Update necessary classes due to CloudAdapter and relocation of changes
Batta32 Jul 14, 2021
18c72cb
Add package-info
Batta32 Jul 14, 2021
683ed68
Add mockito in pom
Batta32 Jul 14, 2021
9ae6d8d
Add CloudAdapter tests
Batta32 Jul 14, 2021
2613e99
Add getCloudAdapter in BotDependencyConfiguration returning a new Clo…
Batta32 Jul 14, 2021
3229e97
Merge branch 'main' into internal/feature/southworks/cloudadapter/base
Batta32 Jul 14, 2021
d6f9afc
Added a Rest Controller for CloudAdapter
ldardick Aug 12, 2021
a896619
Fixed an incorrect recursive call causing a stack overflow
ldardick Aug 12, 2021
667aa8b
Fixed string comparison
ldardick Aug 12, 2021
ffc0df8
Fixed return types for CompleatableFuture
ldardick Aug 12, 2021
0132fcf
Added CloudAdapterWithInspection
ldardick Aug 12, 2021
196cc60
Fixed incorrect type reference in CloudAdapterWithErrorHandler
ldardick Aug 11, 2021
d1b9035
Add UserTokenAccess client and rewire OAuthPrompt (Mirror C# PR MS5213)
matiasroldan6 Aug 10, 2021
541de51
Add evaluation for instanceof UserTokenProvider in methods
matiasroldan6 Aug 11, 2021
ff85f8a
Add properties check in signOutUser
matiasroldan6 Aug 12, 2021
9d360b2
Add UserTokenAccessTests
matiasroldan6 Aug 13, 2021
90ed734
Roll back imports reorder
matiasroldan6 Aug 17, 2021
9ab6e89
Remove unused imports
matiasroldan6 Aug 17, 2021
a33f04c
Removed unused import
ldardick Aug 17, 2021
7a0f861
Fixed turn state key reference
ldardick Aug 17, 2021
546cb29
Change key to String in UserTokenAccessTests
matiasroldan6 Aug 17, 2021
1c3f5c7
Add sendMessageToTeamsChannel overload with CloudAdapter support
matiasroldan6 Aug 18, 2021
248cc89
Added test cases for ParameterizedBotFrameworkAuthentication
FedericoBernal Aug 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added test cases for ParameterizedBotFrameworkAuthentication
  • Loading branch information
FedericoBernal authored and ldardick committed Aug 20, 2021
commit 248cc89406594ca604cac5676a428461e9ddb69e
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package com.microsoft.bot.connector.authentication;

import com.microsoft.bot.connector.Channels;
import com.microsoft.bot.schema.Activity;

import com.microsoft.bot.schema.ChannelAccount;
import com.microsoft.bot.schema.RoleTypes;
import okhttp3.OkHttpClient;
import org.junit.Test;
import org.mockito.Mockito;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

import static org.junit.Assert.*;

public class ParameterizedBotFrameworkAuthenticationTest {
private final String appId = "123";
private final String appPassword = "test";
private final String audienceEmail = "[email protected]";
private final String callerId = "42";
private final String tokenIssuer = "ABC123";
private final String url = "https://example.org/example";
private final Boolean validateAuth = true;
private final String authHeader = "Auth Header";
private final String channelIdHeader = "Channel Id Header";

@Test
public void getOriginatingAudience_withAuthenticationEnabled_shouldMatch() {
PasswordServiceClientCredentialFactory passwordServiceClientCredentialFactory = new PasswordServiceClientCredentialFactory(appId, appPassword);

AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
ParameterizedBotFrameworkAuthentication parameterizedBotFrameworkAuthentication = new ParameterizedBotFrameworkAuthentication(
validateAuth, audienceEmail, audienceEmail, tokenIssuer,
url, audienceEmail, audienceEmail, callerId, passwordServiceClientCredentialFactory,
authenticationConfiguration, new OkHttpClient());

String originatedAudience = parameterizedBotFrameworkAuthentication.getOriginatingAudience();
assertEquals(audienceEmail, originatedAudience);
}

@Test
public void authenticateChannelRequest_withAuthenticationEnabledAndNoHeader_shouldNotBeNull() {
PasswordServiceClientCredentialFactory passwordServiceClientCredentialFactory = new PasswordServiceClientCredentialFactory();

AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
ParameterizedBotFrameworkAuthentication parameterizedBotFrameworkAuthentication = new ParameterizedBotFrameworkAuthentication(
validateAuth, audienceEmail, audienceEmail, tokenIssuer,
url, audienceEmail, audienceEmail, callerId, passwordServiceClientCredentialFactory,
authenticationConfiguration, new OkHttpClient());
ClaimsIdentity claims = parameterizedBotFrameworkAuthentication
.authenticateChannelRequest(null).join();

assertNotNull(claims);
assertTrue(claims.isAuthenticated());
assertEquals(AuthenticationConstants.ANONYMOUS_AUTH_TYPE, claims.getIssuer());
}

@Test
public void authenticateChannelRequest_withAuthenticationDisabled_shouldThrowAnError(){
PasswordServiceClientCredentialFactory passwordServiceClientCredentialFactory = Mockito.mock(PasswordServiceClientCredentialFactory.class);
Mockito.when(passwordServiceClientCredentialFactory.isAuthenticationDisabled()).thenReturn(CompletableFuture.completedFuture(false));
AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();

ParameterizedBotFrameworkAuthentication parameterizedBotFrameworkAuthentication = new ParameterizedBotFrameworkAuthentication(
validateAuth, audienceEmail, audienceEmail, tokenIssuer,
url, audienceEmail, audienceEmail, callerId, passwordServiceClientCredentialFactory,
authenticationConfiguration, new OkHttpClient());

assertThrows(CompletionException.class, () -> {
parameterizedBotFrameworkAuthentication.authenticateChannelRequest(null).join();;
});
}

@Test
public void authenticateRequest_withAuthenticationEnabled_shouldNotBeNull(){
PasswordServiceClientCredentialFactory passwordServiceClientCredentialFactory = new PasswordServiceClientCredentialFactory(appId, appPassword);

AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
ParameterizedBotFrameworkAuthentication parameterizedBotFrameworkAuthentication = new ParameterizedBotFrameworkAuthentication(
validateAuth, audienceEmail, audienceEmail, tokenIssuer,
url, audienceEmail, audienceEmail, callerId, passwordServiceClientCredentialFactory,
authenticationConfiguration, new OkHttpClient());

Activity activity = Activity.createConversationUpdateActivity();
activity.setChannelId(Channels.EMULATOR);
ChannelAccount channelAccount = new ChannelAccount();
RoleTypes roleTypes = RoleTypes.SKILL;
channelAccount.setRole(roleTypes);
activity.setRecipient(channelAccount);

AuthenticateRequestResult result = parameterizedBotFrameworkAuthentication.authenticateRequest(activity,
null).join();
assertNotNull(result);
assertTrue(result.getClaimsIdentity().isAuthenticated());
assertEquals(AuthenticationConstants.ANONYMOUS_AUTH_TYPE, result.getClaimsIdentity().getIssuer());
}

@Test
public void authenticateRequest_shouldNotBeNull() {
PasswordServiceClientCredentialFactory passwordServiceClientCredentialFactory = new PasswordServiceClientCredentialFactory(appId, appPassword);

AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
ParameterizedBotFrameworkAuthentication parameterizedBotFrameworkAuthentication = new ParameterizedBotFrameworkAuthentication(
validateAuth, audienceEmail, audienceEmail, tokenIssuer,
url, audienceEmail, audienceEmail, callerId, passwordServiceClientCredentialFactory,
authenticationConfiguration, new OkHttpClient());

assertNotNull(parameterizedBotFrameworkAuthentication.authenticateRequest(Activity.createConversationUpdateActivity(),
authHeader));
}

@Test
public void authenticateStreamingRequest_withNoChannelId_shouldNotBeNull() {
PasswordServiceClientCredentialFactory passwordServiceClientCredentialFactory = new PasswordServiceClientCredentialFactory(appId, appPassword);

AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
ParameterizedBotFrameworkAuthentication parameterizedBotFrameworkAuthentication = new ParameterizedBotFrameworkAuthentication(
validateAuth, audienceEmail, audienceEmail, tokenIssuer,
url, audienceEmail, audienceEmail, callerId, passwordServiceClientCredentialFactory,
authenticationConfiguration, new OkHttpClient());

assertThrows(CompletionException.class, () -> parameterizedBotFrameworkAuthentication.authenticateStreamingRequest(authHeader, "").join());
}

@Test
public void authenticateStreamingRequest_withAuthenticationDisabled_shouldThrowAnError(){
PasswordServiceClientCredentialFactory passwordServiceClientCredentialFactory = Mockito.mock(PasswordServiceClientCredentialFactory.class);
Mockito.when(passwordServiceClientCredentialFactory.isAuthenticationDisabled()).thenReturn(CompletableFuture.completedFuture(false));
AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();

ParameterizedBotFrameworkAuthentication parameterizedBotFrameworkAuthentication = new ParameterizedBotFrameworkAuthentication(
validateAuth, audienceEmail, audienceEmail, tokenIssuer,
url, audienceEmail, audienceEmail, callerId, passwordServiceClientCredentialFactory,
authenticationConfiguration, new OkHttpClient());

assertThrows(CompletionException.class, () -> {
parameterizedBotFrameworkAuthentication.authenticateStreamingRequest(authHeader, null).join();
});
}

@Test
public void createConnectorFactory_shouldNotBeNull() {
PasswordServiceClientCredentialFactory passwordServiceClientCredentialFactory = new PasswordServiceClientCredentialFactory(appId, appPassword);

AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
ParameterizedBotFrameworkAuthentication parameterizedBotFrameworkAuthentication = new ParameterizedBotFrameworkAuthentication(
validateAuth, audienceEmail, audienceEmail, tokenIssuer,
url, audienceEmail, audienceEmail, callerId, passwordServiceClientCredentialFactory,
authenticationConfiguration, new OkHttpClient());

assertNotNull(parameterizedBotFrameworkAuthentication.createConnectorFactory(SkillValidation.createAnonymousSkillClaim()));
}

@Test
public void createUserTokenClient_shouldThrowAnError() {
PasswordServiceClientCredentialFactory passwordServiceClientCredentialFactory = new PasswordServiceClientCredentialFactory(appId, appPassword);

AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
ParameterizedBotFrameworkAuthentication parameterizedBotFrameworkAuthentication = new ParameterizedBotFrameworkAuthentication(
validateAuth, audienceEmail, audienceEmail, tokenIssuer,
url, audienceEmail, audienceEmail, callerId, passwordServiceClientCredentialFactory,
authenticationConfiguration, new OkHttpClient());

assertThrows(IllegalArgumentException.class, () -> {
parameterizedBotFrameworkAuthentication.createUserTokenClient(SkillValidation.createAnonymousSkillClaim()).join();
});
}

@Test
public void createBotFrameworkClient_shouldNotBeNull() {
PasswordServiceClientCredentialFactory passwordServiceClientCredentialFactory = new PasswordServiceClientCredentialFactory(appId, appPassword);

AuthenticationConfiguration authenticationConfiguration = new AuthenticationConfiguration();
ParameterizedBotFrameworkAuthentication parameterizedBotFrameworkAuthentication = new ParameterizedBotFrameworkAuthentication(
validateAuth, audienceEmail, audienceEmail, tokenIssuer,
url, audienceEmail, audienceEmail, callerId, passwordServiceClientCredentialFactory,
authenticationConfiguration, new OkHttpClient());

assertNotNull(parameterizedBotFrameworkAuthentication.createBotFrameworkClient());
}
}