} from '../../../../src/charging-station/ocpp/auth/types/AuthTypes.js'
import { OCPPVersion } from '../../../../src/types/ocpp/OCPPVersion.js'
import { createMockChargingStation } from '../../ChargingStationTestUtils.js'
-import {
- createMockAuthRequest,
- createMockOCPP16Identifier,
- createMockOCPP20Identifier,
-} from './helpers/MockFactories.js'
+import { createMockAuthRequest, createMockIdentifier } from './helpers/MockFactories.js'
await describe('OCPP Authentication Integration Tests', async () => {
let mockChargingStation16: ChargingStation
const request = createMockAuthRequest({
connectorId: 1,
context: AuthContext.TRANSACTION_START,
- identifier: createMockOCPP16Identifier('VALID_ID_123'),
+ identifier: createMockIdentifier(OCPPVersion.VERSION_16, 'VALID_ID_123'),
})
const result = await authService.authenticate(request)
const request = createMockAuthRequest({
connectorId: 1,
context,
- identifier: createMockOCPP16Identifier(`CONTEXT_TEST_${context}`),
+ identifier: createMockIdentifier(OCPPVersion.VERSION_16, `CONTEXT_TEST_${context}`),
})
const result = await authService.authenticate(request)
const authService = new OCPPAuthServiceImpl(mockChargingStation16)
const request = createMockAuthRequest({
connectorId: 1,
- identifier: createMockOCPP16Identifier('AUTH_DIRECT_TEST'),
+ identifier: createMockIdentifier(OCPPVersion.VERSION_16, 'AUTH_DIRECT_TEST'),
})
const result = await authService.authorize(request)
const request = createMockAuthRequest({
connectorId: 2,
context: AuthContext.TRANSACTION_START,
- identifier: createMockOCPP20Identifier('VALID_ID_456'),
+ identifier: createMockIdentifier(OCPPVersion.VERSION_20, 'VALID_ID_456'),
})
const result = await authService.authenticate(request)
const request = createMockAuthRequest({
connectorId: 2,
context,
- identifier: createMockOCPP20Identifier(`V20_CONTEXT_${context}`),
+ identifier: createMockIdentifier(OCPPVersion.VERSION_20, `V20_CONTEXT_${context}`),
})
const result = await authService.authenticate(request)
const request = createMockAuthRequest({
connectorId: 1,
context: i % 2 === 0 ? AuthContext.TRANSACTION_START : AuthContext.TRANSACTION_STOP,
- identifier: createMockOCPP16Identifier(`CONCURRENT_${String(i)}`),
+ identifier: createMockIdentifier(OCPPVersion.VERSION_16, `CONCURRENT_${String(i)}`),
})
promises.push(authService.authenticate(request))
}
} from '../../../../../src/charging-station/ocpp/auth/types/AuthTypes.js'
import { OCPP16AuthorizationStatus } from '../../../../../src/types/ocpp/1.6/Transaction.js'
import { OCPPVersion } from '../../../../../src/types/ocpp/OCPPVersion.js'
-import {
- createMockAuthorizationResult,
- createMockOCPP16Identifier,
-} from '../helpers/MockFactories.js'
+import { createMockAuthorizationResult, createMockIdentifier } from '../helpers/MockFactories.js'
await describe('OCPP16AuthAdapter', async () => {
let adapter: OCPP16AuthAdapter
const idTag = 'TEST_ID_TAG'
const result = adapter.convertToUnifiedIdentifier(idTag)
- const expected = createMockOCPP16Identifier(idTag)
+ const expected = createMockIdentifier(OCPPVersion.VERSION_16, idTag)
expect(result.value).toBe(expected.value)
expect(result.type).toBe(expected.type)
expect(result.ocppVersion).toBe(expected.ocppVersion)
await describe('convertFromUnifiedIdentifier', async () => {
await it('should convert unified identifier to OCPP 1.6 idTag', () => {
- const identifier = createMockOCPP16Identifier('TEST_ID_TAG')
+ const identifier = createMockIdentifier(OCPPVersion.VERSION_16, 'TEST_ID_TAG')
const result = adapter.convertFromUnifiedIdentifier(identifier)
expect(result).toBe('TEST_ID_TAG')
await describe('isValidIdentifier', async () => {
await it('should validate correct OCPP 1.6 identifier', () => {
- const identifier = createMockOCPP16Identifier('VALID_TAG')
+ const identifier = createMockIdentifier(OCPPVersion.VERSION_16, 'VALID_TAG')
expect(adapter.isValidIdentifier(identifier)).toBe(true)
})
await it('should reject identifier with empty value', () => {
- const identifier = createMockOCPP16Identifier('')
+ const identifier = createMockIdentifier(OCPPVersion.VERSION_16, '')
expect(adapter.isValidIdentifier(identifier)).toBe(false)
})
await it('should reject identifier exceeding max length (20 chars)', () => {
- const identifier = createMockOCPP16Identifier('THIS_TAG_IS_TOO_LONG_FOR_OCPP16')
+ const identifier = createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'THIS_TAG_IS_TOO_LONG_FOR_OCPP16'
+ )
expect(adapter.isValidIdentifier(identifier)).toBe(false)
})
await it('should reject non-ID_TAG types', () => {
- const identifier = createMockOCPP16Identifier('TEST_TAG', IdentifierType.CENTRAL)
+ const identifier = createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'TEST_TAG',
+ IdentifierType.CENTRAL
+ )
expect(adapter.isValidIdentifier(identifier)).toBe(false)
})
await describe('authorizeRemote', async () => {
await it('should perform remote authorization successfully', async () => {
- const identifier = createMockOCPP16Identifier('VALID_TAG')
+ const identifier = createMockIdentifier(OCPPVersion.VERSION_16, 'VALID_TAG')
const result = await adapter.authorizeRemote(identifier, 1, 123)
return Promise.reject(new Error('Network error'))
}
- const identifier = createMockOCPP16Identifier('TEST_TAG')
+ const identifier = createMockIdentifier(OCPPVersion.VERSION_16, 'TEST_TAG')
const result = await adapter.authorizeRemote(identifier, 1)
RequestStartStopStatusEnumType,
} from '../../../../../src/types/ocpp/2.0/Transaction.js'
import { OCPPVersion } from '../../../../../src/types/ocpp/OCPPVersion.js'
-import {
- createMockAuthorizationResult,
- createMockOCPP20Identifier,
-} from '../helpers/MockFactories.js'
+import { createMockAuthorizationResult, createMockIdentifier } from '../helpers/MockFactories.js'
await describe('OCPP20AuthAdapter', async () => {
let adapter: OCPP20AuthAdapter
}
const result = adapter.convertToUnifiedIdentifier(idToken)
- const expected = createMockOCPP20Identifier('TEST_TOKEN')
+ const expected = createMockIdentifier(OCPPVersion.VERSION_20, 'TEST_TOKEN')
expect(result.value).toBe(expected.value)
expect(result.type).toBe(IdentifierType.ID_TAG)
await it('should convert string to unified identifier', () => {
const result = adapter.convertToUnifiedIdentifier('STRING_TOKEN')
- const expected = createMockOCPP20Identifier('STRING_TOKEN')
+ const expected = createMockIdentifier(OCPPVersion.VERSION_20, 'STRING_TOKEN')
expect(result.value).toBe(expected.value)
expect(result.type).toBe(expected.type)
await describe('convertFromUnifiedIdentifier', async () => {
await it('should convert unified identifier to OCPP 2.0 IdToken', () => {
- const identifier = createMockOCPP20Identifier('CENTRAL_TOKEN', IdentifierType.CENTRAL)
+ const identifier = createMockIdentifier(
+ OCPPVersion.VERSION_20,
+ 'CENTRAL_TOKEN',
+ IdentifierType.CENTRAL
+ )
const result = adapter.convertFromUnifiedIdentifier(identifier)
})
await it('should map E_MAID type correctly', () => {
- const identifier = createMockOCPP20Identifier('EMAID_TOKEN', IdentifierType.E_MAID)
+ const identifier = createMockIdentifier(
+ OCPPVersion.VERSION_20,
+ 'EMAID_TOKEN',
+ IdentifierType.E_MAID
+ )
const result = adapter.convertFromUnifiedIdentifier(identifier)
})
await it('should handle ID_TAG to Local mapping', () => {
- const identifier = createMockOCPP20Identifier('LOCAL_TAG')
+ const identifier = createMockIdentifier(OCPPVersion.VERSION_20, 'LOCAL_TAG')
const result = adapter.convertFromUnifiedIdentifier(identifier)
await describe('isValidIdentifier', async () => {
await it('should validate correct OCPP 2.0 identifier', () => {
- const identifier = createMockOCPP20Identifier('VALID_TOKEN', IdentifierType.CENTRAL)
+ const identifier = createMockIdentifier(
+ OCPPVersion.VERSION_20,
+ 'VALID_TOKEN',
+ IdentifierType.CENTRAL
+ )
expect(adapter.isValidIdentifier(identifier)).toBe(true)
})
await it('should reject identifier with empty value', () => {
- const identifier = createMockOCPP20Identifier('', IdentifierType.CENTRAL)
+ const identifier = createMockIdentifier(OCPPVersion.VERSION_20, '', IdentifierType.CENTRAL)
expect(adapter.isValidIdentifier(identifier)).toBe(false)
})
await it('should reject identifier exceeding max length (36 chars)', () => {
- const identifier = createMockOCPP20Identifier(
+ const identifier = createMockIdentifier(
+ OCPPVersion.VERSION_20,
'THIS_TOKEN_IS_DEFINITELY_TOO_LONG_FOR_OCPP20_SPECIFICATION',
IdentifierType.CENTRAL
)
]
for (const type of validTypes) {
- const identifier = createMockOCPP20Identifier('VALID_TOKEN', type)
+ const identifier = createMockIdentifier(OCPPVersion.VERSION_20, 'VALID_TOKEN', type)
expect(adapter.isValidIdentifier(identifier)).toBe(true)
}
})
})
)
- const identifier = createMockOCPP20Identifier('VALID_TOKEN', IdentifierType.CENTRAL)
+ const identifier = createMockIdentifier(
+ OCPPVersion.VERSION_20,
+ 'VALID_TOKEN',
+ IdentifierType.CENTRAL
+ )
const result = await adapter.authorizeRemote(identifier, 1, 'tx_123')
})
await it('should handle invalid token gracefully', async () => {
- const identifier = createMockOCPP20Identifier('', IdentifierType.CENTRAL)
+ const identifier = createMockIdentifier(OCPPVersion.VERSION_20, '', IdentifierType.CENTRAL)
const result = await adapter.authorizeRemote(identifier, 1)
value,
})
-/**
- * Create a mock UnifiedIdentifier for OCPP 1.6
- * @param value - Identifier token value (defaults to 'TEST-TAG-001')
- * @param type - Identifier type enum value (defaults to ID_TAG)
- * @returns Mock UnifiedIdentifier configured for OCPP 1.6 protocol
- * @deprecated Use createMockIdentifier(OCPPVersion.VERSION_16, ...) for new code
- */
-export const createMockOCPP16Identifier = (
- value = 'TEST-TAG-001',
- type: IdentifierType = IdentifierType.ID_TAG
-): UnifiedIdentifier => ({
- ocppVersion: OCPPVersion.VERSION_16,
- type,
- value,
-})
-
-/**
- * Create a mock UnifiedIdentifier for OCPP 2.0
- * @param value - Identifier token value (defaults to 'TEST-TAG-001')
- * @param type - Identifier type enum value (defaults to ID_TAG)
- * @returns Mock UnifiedIdentifier configured for OCPP 2.0 protocol
- * @deprecated Use createMockIdentifier(OCPPVersion.VERSION_20, ...) for new code
- */
-export const createMockOCPP20Identifier = (
- value = 'TEST-TAG-001',
- type: IdentifierType = IdentifierType.ID_TAG
-): UnifiedIdentifier => ({
- ocppVersion: OCPPVersion.VERSION_20,
- type,
- value,
-})
-
/**
* Create a mock AuthRequest
* @param overrides - Partial AuthRequest properties to override defaults
* - createMockBlockedAuthorizationResult (BLOCKED)
* - createMockExpiredAuthorizationResult (EXPIRED)
* - createMockConcurrentTxAuthorizationResult (CONCURRENT_TX)
- *
* @param status - Authorization status (defaults to ACCEPTED)
* @param overrides - Partial AuthorizationResult properties to override defaults
* @returns Mock AuthorizationResult with specified status from local list method
AuthorizationStatus,
IdentifierType,
} from '../../../../../src/charging-station/ocpp/auth/types/AuthTypes.js'
+import { OCPPVersion } from '../../../../../src/types/ocpp/OCPPVersion.js'
import {
createMockAuthCache,
createMockAuthorizationResult,
createMockAuthRequest,
+ createMockIdentifier,
createMockLocalAuthListManager,
- createMockOCPP16Identifier,
createTestAuthConfig,
} from '../helpers/MockFactories.js'
await it('should return true when local auth list is enabled', () => {
const config = createTestAuthConfig({ localAuthListEnabled: true })
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('TEST_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(OCPPVersion.VERSION_16, 'TEST_TAG', IdentifierType.ID_TAG),
})
expect(strategy.canHandle(request, config)).toBe(true)
})
await it('should return true when cache is enabled', () => {
const config = createTestAuthConfig({ authorizationCacheEnabled: true })
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('TEST_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(OCPPVersion.VERSION_16, 'TEST_TAG', IdentifierType.ID_TAG),
})
expect(strategy.canHandle(request, config)).toBe(true)
})
await it('should return false when nothing is enabled', () => {
const config = createTestAuthConfig()
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('TEST_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(OCPPVersion.VERSION_16, 'TEST_TAG', IdentifierType.ID_TAG),
})
expect(strategy.canHandle(request, config)).toBe(false)
})
localAuthListEnabled: true,
})
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('LOCAL_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'LOCAL_TAG',
+ IdentifierType.ID_TAG
+ ),
})
const result = await strategy.authenticate(request, config)
const config = createTestAuthConfig({ authorizationCacheEnabled: true })
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('CACHED_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'CACHED_TAG',
+ IdentifierType.ID_TAG
+ ),
})
const result = await strategy.authenticate(request, config)
const request = createMockAuthRequest({
allowOffline: true,
context: AuthContext.TRANSACTION_STOP,
- identifier: createMockOCPP16Identifier('UNKNOWN_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'UNKNOWN_TAG',
+ IdentifierType.ID_TAG
+ ),
})
const result = await strategy.authenticate(request, config)
await it('should return undefined when no local auth available', async () => {
const config = createTestAuthConfig()
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('UNKNOWN_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'UNKNOWN_TAG',
+ IdentifierType.ID_TAG
+ ),
})
const result = await strategy.authenticate(request, config)
import {
createMockAuthCache,
createMockAuthRequest,
- createMockOCPP16Identifier,
+ createMockIdentifier,
createMockOCPPAdapter,
createTestAuthConfig,
} from '../helpers/MockFactories.js'
await it('should return true when remote auth is enabled', () => {
const config = createTestAuthConfig()
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('REMOTE_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'REMOTE_TAG',
+ IdentifierType.ID_TAG
+ ),
})
expect(strategy.canHandle(request, config)).toBe(true)
})
localPreAuthorize: true,
})
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('REMOTE_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'REMOTE_TAG',
+ IdentifierType.ID_TAG
+ ),
})
expect(strategy.canHandle(request, config)).toBe(false)
})
const strategyNoAdapters = new RemoteAuthStrategy()
const config = createTestAuthConfig()
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('REMOTE_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'REMOTE_TAG',
+ IdentifierType.ID_TAG
+ ),
})
expect(strategyNoAdapters.canHandle(request, config)).toBe(false)
})
await it('should authenticate using OCPP 1.6 adapter', async () => {
const config = createTestAuthConfig({ authorizationCacheEnabled: true })
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('REMOTE_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'REMOTE_TAG',
+ IdentifierType.ID_TAG
+ ),
})
const result = await strategy.authenticate(request, config)
authorizationCacheLifetime: 300,
})
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('CACHE_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'CACHE_TAG',
+ IdentifierType.ID_TAG
+ ),
})
await strategy.authenticate(request, config)
const config = createTestAuthConfig()
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('UNAVAILABLE_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'UNAVAILABLE_TAG',
+ IdentifierType.ID_TAG
+ ),
})
const result = await strategy.authenticate(request, config)
const config = createTestAuthConfig()
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('ERROR_TAG', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(
+ OCPPVersion.VERSION_16,
+ 'ERROR_TAG',
+ IdentifierType.ID_TAG
+ ),
})
const result = await strategy.authenticate(request, config)
const config = createTestAuthConfig()
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('TEST', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(OCPPVersion.VERSION_16, 'TEST', IdentifierType.ID_TAG),
})
expect(newStrategy.canHandle(request, config)).toBe(true)
const config = createTestAuthConfig()
const request = createMockAuthRequest({
- identifier: createMockOCPP16Identifier('TEST', IdentifierType.ID_TAG),
+ identifier: createMockIdentifier(OCPPVersion.VERSION_16, 'TEST', IdentifierType.ID_TAG),
})
expect(strategy.canHandle(request, config)).toBe(false)