Fix transactions unit tests
MODIFY
src/authorization/Authorizations.ts
src/authorization/Authorizations.ts
@@ -704,7 +704,7 @@ export default class Authorizations {
// Access Control Enabled?
if (!chargingStation.siteArea.accessControl) {
// No ACL: Always try to get the user
- return await UserStorage.getUserByTagId(tenantID, tagID);
+ return UserStorage.getUserByTagId(tenantID, tagID);
}
// Site -----------------------------------------------------
chargingStation.siteArea.site = chargingStation.siteArea.site ?
@@ -775,8 +775,9 @@ export default class Authorizations {
}
// Check Auth
if (tag.user.issuer && authAction) {
+ const user = await UserStorage.getUser(tenantID, tag.user.id, { withTag: true });
// Build the JWT Token
- const userToken = await Authorizations.buildUserToken(tenantID, tag.user);
+ const userToken = await Authorizations.buildUserToken(tenantID, user);
// Authorized?
const context = {
user: transaction ? transaction.userID : null,

MODIFY
src/authorization/AuthorizationsDefinition.ts
src/authorization/AuthorizationsDefinition.ts
@@ -45,7 +45,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
{
resource: Entity.CHARGING_STATION, action: [Action.CREATE, Action.READ, Action.UPDATE, Action.DELETE,
Action.RESET, Action.CLEAR_CACHE, Action.GET_CONFIGURATION, Action.CHANGE_CONFIGURATION,
- Action.REMOTE_START_TRANSACTION, Action.REMOTE_STOP_TRANSACTION, Action.UNLOCK_CONNECTOR,
+ Action.REMOTE_START_TRANSACTION, Action.REMOTE_STOP_TRANSACTION,Action.STOP_TRANSACTION,Action.START_TRANSACTION, Action.UNLOCK_CONNECTOR,
Action.AUTHORIZE, Action.SET_CHARGING_PROFILE, Action.GET_COMPOSITE_SCHEDULE, Action.CLEAR_CHARGING_PROFILE,
Action.GET_DIAGNOSTICS, Action.UPDATE_FIRMWARE, Action.EXPORT_PARAMS, Action.CHANGE_AVAILABILITY], attributes: ['*']
},
@@ -135,7 +135,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
},
{
resource: Entity.CHARGING_STATION,
- action: [Action.REMOTE_START_TRANSACTION, Action.AUTHORIZE],
+ action: [Action.REMOTE_START_TRANSACTION, Action.AUTHORIZE, Action.START_TRANSACTION],
attributes: ['*'],
condition: {
Fn: 'OR',
@@ -155,7 +155,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
},
{
resource: Entity.CHARGING_STATION,
- action: Action.REMOTE_STOP_TRANSACTION,
+ action: [Action.REMOTE_STOP_TRANSACTION, Action.STOP_TRANSACTION],
attributes: ['*'],
condition: {
Fn: 'OR',
@@ -262,7 +262,7 @@ const AUTHORIZATION_DEFINITION: AuthorizationDefinition = {
action: [Action.UPDATE, Action.DELETE,
Action.RESET, Action.CLEAR_CACHE, Action.GET_CONFIGURATION, Action.CHANGE_CONFIGURATION,
Action.SET_CHARGING_PROFILE, Action.GET_COMPOSITE_SCHEDULE, Action.CLEAR_CHARGING_PROFILE,
- Action.GET_DIAGNOSTICS, Action.UPDATE_FIRMWARE, Action.REMOTE_STOP_TRANSACTION, Action.EXPORT_PARAMS,
+ Action.GET_DIAGNOSTICS, Action.UPDATE_FIRMWARE, Action.REMOTE_STOP_TRANSACTION,Action.STOP_TRANSACTION,, Action.EXPORT_PARAMS,
Action.CHANGE_AVAILABILITY],
attributes: ['*'],
condition: { Fn: 'LIST_CONTAINS', args: { 'sitesAdmin': '$.site' } }

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -553,7 +553,7 @@ export default class OCPPService {
startTransaction.timezone = Utils.getTimezone(chargingStation.coordinates);
// Check Authorization with Tag ID
const user = await Authorizations.isAuthorizedToStartTransaction(
- headers.tenantID, chargingStation, startTransaction.tagID, ServerAction.START_TRANSACTION);
+ headers.tenantID, chargingStation, startTransaction.tagID, ServerAction.START_TRANSACTION, Action.START_TRANSACTION);
if (user) {
startTransaction.userID = user.id;
}
@@ -761,7 +761,7 @@ export default class OCPPService {
if (!stoppedByCentralSystem) {
// Check and get users
const users = await Authorizations.isAuthorizedToStopTransaction(
- headers.tenantID, chargingStation, transaction, tagId, ServerAction.STOP_TRANSACTION);
+ headers.tenantID, chargingStation, transaction, tagId, ServerAction.STOP_TRANSACTION, Action.STOP_TRANSACTION);
user = users.user;
alternateUser = users.alternateUser;
} else {

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -100,6 +100,8 @@ export enum Action {
SYNCHRONIZE_CAR_CATALOGS = 'SynchronizeCarCatalogs',
REMOTE_START_TRANSACTION = 'RemoteStartTransaction',
REMOTE_STOP_TRANSACTION = 'RemoteStopTransaction',
+ START_TRANSACTION = 'StartTransaction',
+ STOP_TRANSACTION = 'StopTransaction',
UNLOCK_CONNECTOR = 'UnlockConnector',
AUTHORIZE = 'Authorize',
SET_CHARGING_PROFILE = 'SetChargingProfile',

MODIFY
test/api/OCPPAllVersionsTest.ts
test/api/OCPPAllVersionsTest.ts
@@ -341,19 +341,19 @@ describe('OCPP tests (all versions)', function() {
});
- // describe('Where unassigned basic user', () => {
+ describe('Where unassigned basic user', () => {
- // before(() => {
- // testData.ocppCommonTests.setUsers(
- // testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER_UNASSIGNED)
- // );
- // });
+ before(() => {
+ testData.ocppCommonTests.setUsers(
+ testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER_UNASSIGNED)
+ );
+ });
- // it('Should not authorize transaction', async () => {
- // await testData.ocppCommonTests.testStartTransaction(false);
- // });
+ it('Should not authorize transaction', async () => {
+ await testData.ocppCommonTests.testStartTransaction(false);
+ });
- // });
+ });
describe('Where admin user', () => {
@@ -512,19 +512,19 @@ describe('OCPP tests (all versions)', function() {
});
- // describe('Where unassigned basic user', () => {
+ describe('Where unassigned basic user', () => {
- // before(() => {
- // testData.ocppCommonTests.setUsers(
- // testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER_UNASSIGNED)
- // );
- // });
+ before(() => {
+ testData.ocppCommonTests.setUsers(
+ testData.tenantContext.getUserContext(ContextDefinition.USER_CONTEXTS.BASIC_USER_UNASSIGNED)
+ );
+ });
- // it('Should not authorize transaction', async () => {
- // await testData.ocppCommonTests.testStartTransaction(false);
- // });
+ it('Should not authorize transaction', async () => {
+ await testData.ocppCommonTests.testStartTransaction(false);
+ });
- // });
+ });
describe('Where admin user', () => {

Fix transactions unit tests