Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with MrHorse.orPolicy in additional endpoint #233

Closed
hmenzagh opened this issue Mar 26, 2020 · 4 comments
Closed

Issue with MrHorse.orPolicy in additional endpoint #233

hmenzagh opened this issue Mar 26, 2020 · 4 comments

Comments

@hmenzagh
Copy link
Contributor

hmenzagh commented Mar 26, 2020

When I use a MrHorse.orPolicy in an additional endpoint I get an error message.

Version : 1.9

code sample:

extraEndpoints: [
	(server, options, model, logger) => {
		const Log = logger.bind('TimeMachine');
		Log.note('Generating TimeMachine endpoint for userClause');
		server.route({
			method: 'POST',
			path: '/userClause/timeMachine',
			config: {
				handler: async request => clausesTimeMachineHandler(
					request, model.models.userClause, Log,
				),
				validate: { payload: clausesTimeMachineSchema },
				tags: ['api', 'userClause', 'timeMachine'],
				plugins: {
					'hapi-swagger': {},
					policies: ['userAuth', MrHorse.orPolicy('objectAuth', 'adminPowered')],
					model: model.models.userClause, // is not passed automatically
				},
			},
		});
	},
],

error message:

{
    "statusCode": 403,
    "error": "Forbidden",
    "message": "Cannot read property 'status' of undefined"
}

My policy functions are not executed, and I see that the console.log of results (L:381 in MrHorse's index.js) is empty ({}) witch explains the error message (Crash L:384).

I did not dig further and will avoid using MrHorse.orPolicy for the time being.

Would it be a quick fix ?

(Thanks for the great work btw)

@hmenzagh hmenzagh changed the title issue with MrHorse.orPolicy in additional endpoint Issue with MrHorse.orPolicy in additional endpoint Mar 26, 2020
@JKHeadley
Copy link
Owner

@hmenzagh it's hard to say. I don't have much experience with the MrHorse.orPolicy feature. If you could provide the full code needed to replicate the issue (model and policy files) I can try to look into it.

@hmenzagh
Copy link
Contributor Author

hmenzagh commented Mar 27, 2020

I guess no code setup is really necessary, just import mrhorse and add something like policies: ['userAuth', MrHorse.orPolicy('objectAuth', 'adminPowered')], (as I said the policies aren't executed)
if you really need the full code I'll try tu put up something asap

@JKHeadley
Copy link
Owner

@hmenzagh yes that would be very helpful. If you could provide a very basic example (full code) to replicate the issue that will help a lot since my resources are very limited.

@hmenzagh
Copy link
Contributor Author

I was preparing an example repo and I dont know what changed but the issue is not reproducible anymore, I will re-open if it rises up again.
Sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants