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

C2S/SASL #4101

Merged
merged 3 commits into from
Aug 24, 2023
Merged

C2S/SASL #4101

merged 3 commits into from
Aug 24, 2023

Conversation

NelsonVides
Copy link
Collaborator

An initial refactoring of SASL out of C2S.

I chose accumulators as the SASL state because they also enable tracing trough refs and timing through their timestamps.

@mongoose-im

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Aug 15, 2023

Codecov Report

Patch coverage: 89.65% and project coverage change: -0.01% ⚠️

Comparison is base (0133bc9) 83.92% compared to head (abb89da) 83.91%.

Additional details and impacted files
@@                Coverage Diff                @@
##           feature/sasl2    #4101      +/-   ##
=================================================
- Coverage          83.92%   83.91%   -0.01%     
=================================================
  Files                551      552       +1     
  Lines              33596    33642      +46     
=================================================
+ Hits               28195    28232      +37     
- Misses              5401     5410       +9     
Files Changed Coverage Δ
src/c2s/mongoose_c2s_stanzas.erl 96.36% <ø> (ø)
src/hooks/mongoose_hooks.erl 94.92% <ø> (ø)
src/c2s/mongoose_c2s.erl 87.15% <83.72%> (-1.03%) ⬇️
src/c2s/mongoose_c2s_sasl.erl 95.45% <95.45%> (ø)

... and 8 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mongoose-im

This comment was marked as outdated.

@NelsonVides NelsonVides marked this pull request as ready for review August 21, 2023 07:57
Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's nice to see how the SASL parts are being extracted. I added some comments.


-spec handle_sasl_abort(data(), mongoose_acc:t(), retries()) -> fsm_res().
handle_sasl_abort(StateData, SaslAcc, Retries) ->
Error = #{server_out => <<"aborted">>, maybe_username => StateData#c2s_data.jid},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we call JID "username"?

handle_sasl_failure(#c2s_data{host_type = HostType, lserver = LServer} = StateData, SaslAcc,
#{server_out := ServerOut, maybe_username := Username}, Retries) ->
?LOG_INFO(#{what => auth_failed, text => <<"Failed SASL authentication">>,
jid => Username, c2s_state => StateData}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So is it a JID or user name? I am confused.

handle_sasl_failure(C2SData, Error, Username, _, SaslAcc) ->
LServer = mongoose_c2s:get_lserver(C2SData),
NewJid = jid:make_bare(Username, LServer),
{failure, SaslAcc, #{server_out => Error, maybe_username => NewJid}}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really strange - the code keeps jumping between JID and username - like here between lines 96 and 100.

mongoose_c2s:data(), term(), maybe_username(), maybe_username(), mongoose_acc:t()) -> result().
handle_sasl_failure(_C2SData, Error, undefined, undefined, SaslAcc) ->
{failure, SaslAcc, #{server_out => Error, maybe_username => undefined}};
handle_sasl_failure(_C2SData, Error, undefined, #jid{luser = Username}, SaslAcc) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for sure against the spec (double username). Is it reachable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed it is the only line of code not covered by tests in this module, now it will have 100% coverage, good catch! 😛

@mongoose-im

This comment was marked as outdated.

Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added minor comments.

handle_sasl_failure(C2SData, Error, Username, undefined, SaslAcc);
handle_sasl_step(C2SData, {error, Error}, SaslAcc) ->
Jid = mongoose_c2s:get_jid(C2SData),
handle_sasl_failure(C2SData, Error, undefined, Jid, SaslAcc).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as before, passing Jid while the type is maybe_username().

@@ -119,6 +121,16 @@ message_sent_to_malformed_jid_results_in_error(Config) ->
escalus_assert:is_chat_message(<<"Hi!">>, escalus_client:wait_for_stanza(Bob))
end).

invalid_resource_fails_to_log(Config) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't this already done in a merged PR? Maybe rebase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I did and yet dunno why this shows up here, just rebased again.

@mongoose-im
Copy link
Collaborator

mongoose-im commented Aug 24, 2023

elasticsearch_and_cassandra_25 / elasticsearch_and_cassandra_mnesia / abb89da
Reports root/ big
OK: 369 / Failed: 0 / User-skipped: 38 / Auto-skipped: 0


small_tests_24 / small_tests / abb89da
Reports root / small


small_tests_25 / small_tests / abb89da
Reports root / small


small_tests_25_arm64 / small_tests / abb89da
Reports root / small


ldap_mnesia_24 / ldap_mnesia / abb89da
Reports root/ big
OK: 2275 / Failed: 0 / User-skipped: 831 / Auto-skipped: 0


dynamic_domains_mysql_redis_25 / mysql_redis / abb89da
Reports root/ big
OK: 4202 / Failed: 0 / User-skipped: 116 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_24 / pgsql_mnesia / abb89da
Reports root/ big
OK: 4234 / Failed: 0 / User-skipped: 84 / Auto-skipped: 0


ldap_mnesia_25 / ldap_mnesia / abb89da
Reports root/ big
OK: 2275 / Failed: 0 / User-skipped: 831 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_25 / pgsql_mnesia / abb89da
Reports root/ big
OK: 4234 / Failed: 0 / User-skipped: 84 / Auto-skipped: 0


internal_mnesia_25 / internal_mnesia / abb89da
Reports root/ big
OK: 2421 / Failed: 0 / User-skipped: 685 / Auto-skipped: 0


dynamic_domains_mssql_mnesia_25 / odbc_mssql_mnesia / abb89da
Reports root/ big
OK: 4231 / Failed: 0 / User-skipped: 87 / Auto-skipped: 0


mysql_redis_25 / mysql_redis / abb89da
Reports root/ big
OK: 4603 / Failed: 0 / User-skipped: 111 / Auto-skipped: 0


pgsql_mnesia_24 / pgsql_mnesia / abb89da
Reports root/ big
OK: 4617 / Failed: 1 / User-skipped: 91 / Auto-skipped: 5

bosh_SUITE:essential_https:accept_higher_hold_value
{error,
  {{assertEqual,
     [{module,bosh_SUITE},
      {line,260},
      {expression,"get_bosh_sessions ( )"},
      {expected,[]},
      {value,
        [{bosh_session,<<"5609d62ed9b946b9d86c3c2d98b7bc0a87484cbc">>,
           <8854.10235.0>}]}]},
   [{bosh_SUITE,accept_higher_hold_value,1,
      [{file,"/home/circleci/project/big_tests/tests/bosh_SUITE.erl"},
       {line,260}]},
    {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1783}]},
    {test_server,run_test_case_eval1,6,
      [{file,"test_server.erl"},{line,1292}]},
    {test_server,run_test_case_eval,9,
      [{file,"test_server.erl"},{line,1224}]}]}}

Report log


pgsql_cets_25 / pgsql_cets / abb89da
Reports root/ big
OK: 4593 / Failed: 0 / User-skipped: 121 / Auto-skipped: 0


pgsql_mnesia_25 / pgsql_mnesia / abb89da
Reports root/ big
OK: 4623 / Failed: 0 / User-skipped: 91 / Auto-skipped: 0


mssql_mnesia_25 / odbc_mssql_mnesia / abb89da
Reports root/ big
OK: 4620 / Failed: 0 / User-skipped: 94 / Auto-skipped: 0


pgsql_mnesia_24 / pgsql_mnesia / abb89da
Reports root/ big
OK: 4623 / Failed: 0 / User-skipped: 91 / Auto-skipped: 0

Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 👌

@chrzaszcz chrzaszcz merged commit 389560e into feature/sasl2 Aug 24, 2023
4 checks passed
@chrzaszcz chrzaszcz deleted the c2s/sasl branch August 24, 2023 11:40
@chrzaszcz chrzaszcz added this to the 6.2.0 milestone Dec 11, 2023
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

Successfully merging this pull request may close these issues.

None yet

3 participants