Skip to content

Commit

Permalink
Revert "Allow adding custom auth token for pact verification"
Browse files Browse the repository at this point in the history
This reverts commit d75d6ba.

Reason:

I actually found anther way of replacing the authorization header:
- Use `fromProviderState` Matcher function on consumer side for auth
header. Match `Bearer ${authToken}`, use JWT regex
- On provider side, in state change URL endpoint, generate the token
and return it in the callback under `authToken`
- The provider-generated auth token will be used in the request.

I am leaving this as commit + revert for future reference purposes.
  • Loading branch information
Siim Mardus committed Jun 5, 2024
1 parent d75d6ba commit df5df77
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
17 changes: 5 additions & 12 deletions c_src/pactffi_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,19 +699,12 @@ static ERL_NIF_TERM verify_via_file(ErlNifEnv *env, int argc, const ERL_NIF_TERM
pactffi_verifier_set_no_pacts_is_error(verifierhandle, 0);
pactffi_verifier_set_provider_info(verifierhandle, name, scheme, host, port, path);
pactffi_verifier_add_provider_transport(verifierhandle, protocol, port, path, scheme);

char *auth_token_type = convert_erl_binary_to_c_string(env, argv[9]);
char *auth_token_value = convert_erl_binary_to_c_string(env, argv[10]);
char *auth_header = (char *)malloc((strlen(auth_token_type) + strlen(auth_token_value) + 1) * sizeof(char));
sprintf(auth_header, "%s %s", auth_token_type, auth_token_value);
pactffi_verifier_add_custom_header(verifierhandle, "authorization", auth_header);
free(auth_header);

if (!enif_is_binary(env, argv[11]))
if (!enif_is_binary(env, argv[9]))
{
return enif_make_badarg(env);
}
char *state_path = convert_erl_binary_to_c_string(env, argv[11]);

char *state_path = convert_erl_binary_to_c_string(env, argv[9]);
if (state_path[0] != '\0')
{
pactffi_verifier_set_provider_state(verifierhandle, state_path, 0, 1);
Expand Down Expand Up @@ -882,10 +875,10 @@ static ErlNifFunc nif_funcs[] =
{"msg_given_with_param", 4, msg_given_with_param},
{"msg_with_contents", 3, msg_with_contents},
{"reify_message", 1, reify_message},
{"schedule_async_file_verify", 12, schedule_async_file_verify},
{"schedule_async_file_verify", 10, schedule_async_file_verify},
{"schedule_async_broker_verify", 15, schedule_async_broker_verify},
{"verify_via_broker", 15, verify_via_broker},
{"verify_via_file", 12, verify_via_file}
{"verify_via_file", 10, verify_via_file}
};

ERL_NIF_INIT(pactffi_nif, nif_funcs, NULL, NULL, NULL, NULL)
2 changes: 1 addition & 1 deletion src/pact_escript.escript
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ main([Module, Function | Args]) ->
{[], 0},
Args
),
case length(AList) < 12 of
case length(AList) < 10 of
true ->
AList ++ [<<"">>];
false ->
Expand Down
4 changes: 0 additions & 4 deletions src/pact_verifier.erl
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ verify_pacts(VerifierRef, ProviderOpts, ProviderPortDetails) ->
} = ProviderOpts,
Protocol = maps:get(protocol, ProviderOpts, <<"http">>),
BaseUrl = maps:get(base_url, ProviderOpts, <<"/">>),
AuthTokenType = maps:get(auth_token_type, ProviderOpts, <<"Bearer">>),
AuthTokenValue = maps:get(auth_token_value, ProviderOpts, <<"Token">>),
StateChangeUrl = maps:get(state_change_url, ProviderOpts, <<"">>),
Scheme = maps:get(scheme, ProviderOpts, <<"http">>),
FilePath = maps:get(file_path, PactSourceOpts, undefined),
Expand All @@ -184,8 +182,6 @@ verify_pacts(VerifierRef, ProviderOpts, ProviderPortDetails) ->
Branch,
FilePath,
Protocol,
AuthTokenType,
AuthTokenValue,
StateChangeUrl
],
ArgsString =
Expand Down
20 changes: 10 additions & 10 deletions src/pactffi_nif.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
msg_with_contents/3,
reify_message/1,
get_reified_message/1,
verify_file_pacts/12,
verify_file_pacts/10,
verify_broker_pacts/14,
schedule_async_broker_verify/15,
schedule_async_file_verify/12,
schedule_async_file_verify/10,
verify_via_broker/15,
verify_via_file/12
verify_via_file/10
]).

% Import the NIF functions from the C library
Expand Down Expand Up @@ -70,10 +70,10 @@
msg_given_with_param/4,
msg_with_contents/3,
reify_message/1,
schedule_async_file_verify/12,
schedule_async_file_verify/10,
schedule_async_broker_verify/15,
verify_via_broker/15,
verify_via_file/12
verify_via_file/10
]).
-on_load(init/0).

Expand Down Expand Up @@ -186,30 +186,30 @@ msg_with_contents(_, _, _) ->
reify_message(_) ->
erlang:nif_error("NIF library not loaded").

schedule_async_file_verify(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12) ->
schedule_async_file_verify(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) ->
erlang:nif_error("NIF library not loaded").

schedule_async_broker_verify(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15) ->
erlang:nif_error("NIF library not loaded").

verify_via_file(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12) ->
verify_via_file(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) ->
erlang:nif_error("NIF library not loaded").

verify_via_broker(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15) ->
erlang:nif_error("NIF library not loaded").

verify_file_pacts(
Name, Scheme, Host, Port, Path, Version, Branch, FilePath, Protocol, AuthTokenType, AuthTokenValue, StatePath
Name, Scheme, Host, Port, Path, Version, Branch, FilePath, Protocol, StatePath
) ->
verify_via_file(
Name, Scheme, Host, Port, Path, Version, Branch, FilePath, Protocol, AuthTokenType, AuthTokenValue, StatePath
Name, Scheme, Host, Port, Path, Version, Branch, FilePath, Protocol, StatePath
).
% receive
% Output ->
% Output
% end.
% verify_via_file(
% Name, Scheme, Host, Port, Path, Version, Branch, FilePath, Protocol, Pid, AuthTokenType, AuthTokenValue, StatePath
% Name, Scheme, Host, Port, Path, Version, Branch, FilePath, Protocol, Pid, StatePath
% ).

verify_broker_pacts(
Expand Down

0 comments on commit df5df77

Please sign in to comment.