|
1 | 1 | const { strictEqual } = require('assert');
|
2 | 2 | const { BotFrameworkHttpClient } = require('../');
|
3 |
| -const { AuthenticationConstants, SimpleCredentialProvider, MicrosoftAppCredentials } = require('botframework-connector'); |
| 3 | +const { AuthenticationConstants, GovernmentConstants, JwtTokenValidation, SimpleCredentialProvider, MicrosoftAppCredentials, AppCredentials } = require('botframework-connector'); |
4 | 4 | const nock = require('nock');
|
5 | 5 |
|
6 | 6 | class TestBotFrameworkHttpClient extends BotFrameworkHttpClient {
|
@@ -79,6 +79,52 @@ describe('BotFrameworkHttpClient', function() {
|
79 | 79 | strictEqual(response.status, 200);
|
80 | 80 | });
|
81 | 81 |
|
| 82 | + it('should fail to make call with wrong credentials', async () => { |
| 83 | + |
| 84 | + nock('http://skillUrl') |
| 85 | + .post('/api/good') |
| 86 | + .reply(200, { id: 'some-id' }); |
| 87 | + |
| 88 | + const credentialProvider = new SimpleCredentialProvider('test-app-id', 'test-app-Secret'); |
| 89 | + const client = new TestBotFrameworkHttpClient(credentialProvider, 'channels'); |
| 90 | + try { |
| 91 | + await client.postActivity('fromBotId', 'toBotId', 'http://skillUrl/api/good', 'serviceUrl', 'conversationId', { type: 'message', conversation: { } }); |
| 92 | + } catch(e) { |
| 93 | + strictEqual(e.message, 'BotFrameworkHttpClient.postActivity(): Unable to get appCredentials to connect to the skill'); |
| 94 | + } |
| 95 | + }); |
| 96 | + |
| 97 | + it('should fail to make call when no activity is provided', async () => { |
| 98 | + nock('http://skillUrl') |
| 99 | + .post('/api/good', (body) => body.recipient) |
| 100 | + .reply(200, { id: 'some-id' }); |
| 101 | + |
| 102 | + const credentialProvider = new SimpleCredentialProvider('this-is-not-the-app-id-your-looking-for', '1'); |
| 103 | + const client = new TestBotFrameworkHttpClient(credentialProvider, 'channels'); |
| 104 | + const fromBotId = 'this-is-not-the-app-id-your-looking-for'; |
| 105 | + try { |
| 106 | + await client.postActivity(fromBotId, 'toBotId', 'http://skillUrl/api/good', 'serviceUrl', 'conversationId'); |
| 107 | + } catch(e) { |
| 108 | + strictEqual(e.message, 'BotFrameworkHttpClient.postActivity(): missing activity'); |
| 109 | + } |
| 110 | + }); |
| 111 | + |
| 112 | + it('should fail to make call when activity.conversation is undefined', async () => { |
| 113 | + nock('http://skillUrl') |
| 114 | + .post('/api/good', (body) => body.recipient) |
| 115 | + .reply(200, { id: 'some-id' }); |
| 116 | + |
| 117 | + const credentialProvider = new SimpleCredentialProvider('this-is-not-the-app-id-your-looking-for', '1'); |
| 118 | + const client = new TestBotFrameworkHttpClient(credentialProvider, 'channels'); |
| 119 | + const fromBotId = 'this-is-not-the-app-id-your-looking-for'; |
| 120 | + const activity = { type: 'message' }; |
| 121 | + try { |
| 122 | + await client.postActivity(fromBotId, 'toBotId', 'http://skillUrl/api/good', 'serviceUrl', 'conversationId', activity); |
| 123 | + } catch(e) { |
| 124 | + strictEqual(e.message, 'BotFrameworkHttpClient.postActivity(): Activity must have a ConversationReference'); |
| 125 | + } |
| 126 | + }); |
| 127 | + |
82 | 128 | it('should add empty recipient if missing from activity', async () => {
|
83 | 129 | nock('http://skillUrl')
|
84 | 130 | .post('/api/good', (body) => body.recipient)
|
@@ -107,4 +153,20 @@ describe('BotFrameworkHttpClient', function() {
|
107 | 153 | strictEqual(forwardedActivity.relatesTo, originalRelatesTo);
|
108 | 154 | });
|
109 | 155 | });
|
| 156 | + |
| 157 | + describe('BuildCredentials', () => { |
| 158 | + it('should return credentials when channel service is goverment', async () => { |
| 159 | + const credentialProvider = new SimpleCredentialProvider('', ''); |
| 160 | + const client = new BotFrameworkHttpClient(credentialProvider, 'https://botframework.azure.us'); |
| 161 | + const credentials = await client.buildCredentials('test-app-id', 'test-scope'); |
| 162 | + strictEqual(credentials.oAuthEndpoint, GovernmentConstants.ToChannelFromBotLoginUrl); |
| 163 | + }); |
| 164 | + |
| 165 | + it('should return credentials when channel service different than goverment', async () => { |
| 166 | + const credentialProvider = new SimpleCredentialProvider('', ''); |
| 167 | + const client = new BotFrameworkHttpClient(credentialProvider, 'channels'); |
| 168 | + const credentials = await client.buildCredentials('test-app-id', 'test-scope'); |
| 169 | + strictEqual(credentials.oAuthEndpoint, AuthenticationConstants.ToChannelFromBotLoginUrl); |
| 170 | + }); |
| 171 | + }); |
110 | 172 | });
|
0 commit comments