backend-test-utils: add version field to mock credentials
The mock credentials created by mockCredentials.none(), .user(), and .service() were missing the internal version: 'v1' field. This caused toInternalBackstageCredentials() to throw when used with mock credentials in tests. Signed-off-by: Fredrik Adelöw <freben@gmail.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
+3
-2
@@ -556,13 +556,14 @@ describe('actionsRegistryServiceFactory', () => {
|
||||
input: {
|
||||
name: 'test',
|
||||
},
|
||||
credentials: {
|
||||
credentials: expect.objectContaining({
|
||||
$$type: '@backstage/BackstageCredentials',
|
||||
version: 'v1',
|
||||
principal: {
|
||||
type: 'service',
|
||||
subject: 'user:default/mock',
|
||||
},
|
||||
},
|
||||
}),
|
||||
logger: expect.anything(),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,10 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { mockCredentials } from '@backstage/backend-test-utils';
|
||||
import {
|
||||
createCredentialsWithNonePrincipal,
|
||||
createCredentialsWithServicePrincipal,
|
||||
createCredentialsWithUserPrincipal,
|
||||
toInternalBackstageCredentials,
|
||||
} from './helpers';
|
||||
|
||||
describe('credentials', () => {
|
||||
@@ -82,6 +84,51 @@ describe('credentials', () => {
|
||||
).not.toMatch(/my-token/);
|
||||
});
|
||||
|
||||
it('should convert mock credentials to internal form', () => {
|
||||
expect(
|
||||
toInternalBackstageCredentials(mockCredentials.none()),
|
||||
).toMatchObject({ version: 'v1', principal: { type: 'none' } });
|
||||
|
||||
expect(
|
||||
toInternalBackstageCredentials(mockCredentials.user()),
|
||||
).toMatchObject({
|
||||
version: 'v1',
|
||||
token: mockCredentials.user.token(),
|
||||
principal: { type: 'user', userEntityRef: 'user:default/mock' },
|
||||
});
|
||||
|
||||
expect(
|
||||
toInternalBackstageCredentials(
|
||||
mockCredentials.user('user:default/other'),
|
||||
),
|
||||
).toMatchObject({
|
||||
version: 'v1',
|
||||
token: mockCredentials.user.token('user:default/other'),
|
||||
principal: { type: 'user', userEntityRef: 'user:default/other' },
|
||||
});
|
||||
|
||||
expect(
|
||||
toInternalBackstageCredentials(mockCredentials.limitedUser()),
|
||||
).toMatchObject({
|
||||
version: 'v1',
|
||||
principal: { type: 'user', userEntityRef: 'user:default/mock' },
|
||||
});
|
||||
|
||||
expect(
|
||||
toInternalBackstageCredentials(mockCredentials.service()),
|
||||
).toMatchObject({
|
||||
version: 'v1',
|
||||
principal: { type: 'service', subject: 'external:test-service' },
|
||||
});
|
||||
|
||||
expect(
|
||||
toInternalBackstageCredentials(mockCredentials.service('plugin:other')),
|
||||
).toMatchObject({
|
||||
version: 'v1',
|
||||
principal: { type: 'service', subject: 'plugin:other' },
|
||||
});
|
||||
});
|
||||
|
||||
it('should have a serializable form both as strings and as JSON', () => {
|
||||
const simpleService = createCredentialsWithServicePrincipal('my-service');
|
||||
expect(String(simpleService)).toMatchInlineSnapshot(
|
||||
|
||||
Reference in New Issue
Block a user