view · edit · sidebar · attach · print · history

Index>

20170508-virbac-rack

Summary

Commits

Index

Port Virbac to RACK based SBSM

Evaluating how I can save the authentication received via login in a manner that is accessible, when I use the auth_session. Checking whether this work via a global variable.

Started pry session in bbmb/lib/bbmb/html/util/session.rb BBMB::Html::Util::Session#login:

# relevant stack trace
/home/niklaus/git/bbmb/lib/bbmb/html/util/session.rb:37:in `login'
/home/niklaus/git/bbmb/lib/bbmb/html/state/login.rb:18:in `login'
/home/niklaus/git/sbsm/lib/sbsm/state.rb:197:in `_trigger'
/home/niklaus/git/sbsm/lib/sbsm/state.rb:186:in `trigger'
/home/niklaus/git/sbsm/lib/sbsm/session.rb:222:in `block in process_rack'
/home/niklaus/git/sbsm/lib/sbsm/session.rb:213:in `synchronize'
/home/niklaus/git/sbsm/lib/sbsm/session.rb:213:in `process_rack'
/home/niklaus/git/sbsm/lib/sbsm/app.rb:135:in `call'
# Tried the solution before rack and got
> @user = @app.login(user_input(:email), user_input(:pass))
NoMethodError: undefined method `login' for nil:NilClass
from /home/niklaus/git/bbmb/lib/bbmb/util/server.rb:195:in `login'
# Trying my new solution where I store the auth in the @app. And got
[4] pry(#<BBMB::Html::Util::Session>)> @user = @app.auth.login(user_input(:email), user_input(:pass))     
ArgumentError: wrong number of arguments (given 2, expected 3)
from (druby://virbac.bbmb.ngiger.ch:12003) /usr/local/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/yus-1.0.4/lib/yus/server.rb:24:in `login'

Tried to compare this with a pry session in the before virbac, but there I get the following error (seen in the service log)

error in SBSM::Session#process: /de/bbmb
NoMethodError
undefined method `session' for #<Yus::EntitySession:0x0055a9f2360fa0>
(druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/odba-1.1.2/lib/odba/drbwrapper.rb:28:in `method_missing'
(druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/2.4.0/drb/drb.rb:1624:in `perform_without_block'

The yus/server login method is defined as followed def login(name, password, domain)

Adding the domain parameter solved the problem, see the pry snippet

[6] pry(#<BBMB::Html::Util::Session>)> @user = @app.auth.login(user_input(:email), user_input(:pass), BBMB.config.auth_domain)
=> #<DRb::DRbObject:0x00555fa811a780 @ref=47094204734380, @uri="druby://127.0.0.1:12003">

Now I can continue until being in lib/bbmb/html/state/viral/customer.rb @ line 96 BBMB::Html::State::Viral::Customer#home: where I have problems getting the @user.home attribute

# relevant stack trace
"/home/niklaus/git/bbmb/lib/bbmb/html/state/viral/customer.rb:96:in `home'",
 "/home/niklaus/git/sbsm/lib/sbsm/state.rb:197:in `_trigger'",
 "/home/niklaus/git/sbsm/lib/sbsm/state.rb:186:in `trigger'",
 "/home/niklaus/git/sbsm/lib/sbsm/viralstate.rb:38:in `trigger'",
 "/home/niklaus/git/bbmb/lib/bbmb/html/state/login.rb:19:in `login'",
 "/home/niklaus/git/sbsm/lib/sbsm/state.rb:197:in `_trigger'",
 "/home/niklaus/git/sbsm/lib/sbsm/state.rb:186:in `trigger'",
 "/home/niklaus/git/sbsm/lib/sbsm/session.rb:222:in `block in process_rack'",
 "/home/niklaus/git/sbsm/lib/sbsm/session.rb:213:in `synchronize'",
 "/home/niklaus/git/sbsm/lib/sbsm/session.rb:213:in `process_rack'",
 "/home/niklaus/git/sbsm/lib/sbsm/app.rb:135:in `call'",
[5] pry(#<BBMB::Html::State::Login>)> trigger(@session.user.home || :current_order)
NoMethodError: undefined method `home' for #<Yus::EntitySession:0x0055a9f27ea968>
from (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/odba-1.1.2/lib/odba/drbwrapper.rb:28:in `method_missing'
[6] pry(#<BBMB::Html::State::Login>)> @session.user.home
NoMethodError: undefined method `home' for #<Yus::EntitySession:0x0055a9f27ea968>
from (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/odba-1.1.2/lib/odba/drbwrapper.rb:28:in `method_missing'

Why?

Looks like BBMB::Html::State::Login#login: in bbmb/lib/bbmb/html/state/login.rb has a problem. Followed it via pry

[1] pry(#<BBMB::Html::State::Login>)> reconsider_permissions(@session.login)
session.rb:36:in `login' BBMB::Html::Util::Session login claude.meier@gmx.net 5972659ce6c7f9b2356c0e650c7c40a3  DRb::DRbObject
=> [[".Admin", BBMB::Html::State::Viral::Admin], [".Customer", BBMB::Html::State::Viral::Customer]]
[2] pry(#<BBMB::Html::State::Login>)> trigger(:home)
NoMethodError: undefined method `home' for #<Yus::EntitySession:0x0055a9f2a7db80>
from (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/odba-1.1.2/lib/odba/drbwrapper.rb:28:in `method_missing'

Here we have again the problem that under the mod_ruby based version, the @session.user was set upon login. This worked under davaz.com, because there the login of the sbsm-gem was not overridden. But bbmb overwrites it.

Setting binding.pry in all 4 logout methods of bbmb to see whether we correctly initialize the unkonwn_user attribute. logout is called in the following temporal order

  1. virbac app starts
  2. bbmb/lib/bbmb/html/util/session.rb @ line 42 BBMB::Html::Util::Session#logout
  3. bbmb/lib/bbmb/util/server.rb @ line 202 BBMB::Util::App#logout
  4. virbac shows login screen
  5. Trying to login with a correct user/password
  6. bbmb/lib/bbmb/html/state/login.rb @ line 19 BBMB::Html::State::Login#login

And here we have our problem.

Verified with pry in lib/sbsm/session unknown user that I indeed have a problem to the @unkown_user's home attribute

[1] pry(#<BBMB::Html::Util::Session>)> @unknown_user.class
=> BBMB::Html::Util::KnownUser
[2] pry(#<BBMB::Html::Util::Session>)> @unknown_user.home
undefined method `get_preference' for #<BBMB::Util::App:0x00561001ba4278>
/home/niklaus/git/sbsm/lib/sbsm/session.rb:144:in `method_missing'
/home/niklaus/git/bbmb/lib/bbmb/html/util/known_user.rb:49:in `remote_call'
/home/niklaus/git/bbmb/lib/bbmb/html/util/known_user.rb:22:in `block (2 levels) in <class:KnownUser>'

Must fix this problem. Done by changing in lib/bbmb/html/state/viral/customer.rb the home method to use @session.user.get_preference(:home) instead of @session.user.home

Now the next problem is that I the following error backtrace

NoMethodError: undefined method `navigation' for #<Yus::EntitySession:0x0055a9f2a23108>
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/odba-1.1.2/lib/odba/drbwrapper.rb:28:in `method_missing'
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/2.4.0/drb/drb.rb:1624:in `perform_without_block'
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/2.4.0/drb/drb.rb:1584:in `perform'
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/2.4.0/drb/drb.rb:1668:in `block (2 levels) in main_loop'
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/2.4.0/drb/drb.rb:1664:in `loop'
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/2.4.0/drb/drb.rb:1664:in `block in main_loop'
        /home/niklaus/git/sbsm/lib/sbsm/session.rb:427:in `navigation'
        /home/niklaus/git/sbsm/lib/sbsm/lookandfeel.rb:132:in `navigation'
        /var/www/virbac_rack.bbmb.ch/lib/bbmb/html/util/lookandfeel.rb:473:in `navigation'
        /home/niklaus/git/bbmb/lib/bbmb/html/view/navigation.rb:24:in `build_navigation'
        /home/niklaus/git/bbmb/lib/bbmb/html/view/navigation.rb:20:in `init'

Backtrace means, that we sucessfully authenticated agains YUS, but we are unable to display the answer correctly. Tried lib/bbmb/html/util/lookandfeel.rb to patch the navigation method like this

  def navigation
    begin
      default_value = super
      puts "navigation return #{zone_navigation + default_value}"
       zone_navigation + default_value
    rescue => error
      prefs =  @session.user.get_preference(:navigation)
      puts "navigation returns #{zone_navigation + (prefs ? prefs : [])}"
      zone_navigation + (prefs ? prefs : [])
    end
  end

But this leads to the situation that we display a logged in user, but that the home does not display the actual order. Screen looks like

When clicking on the link "Warenkorb (Home)" I got an exception about undefined Module BBMB::Promotion. Fixed this by adding a require for all used BBMB::Model classes in lib/bbmb/util/server.rb. Now the Warenkorb displays correctly. Also clicking on each of the other links on right of Warenkorb the following produce errors

  • Katalog
  • Promotionen
  • Kalkulieren

In each case we cannot use the BBMB.persistence attribute is nil instead of pointing to the ODBA persistence. After adding a definition (see below) for BBMB.persistence in bbmb/lib/bbmb/util/server.rb the problems went away.

+  def self.persistence
+    @@persistence ||= BBMB::Persistence::ODBA
+  end

Fixed the problem with the missing "Warenkorb (Home) for a normal user. The logout link is not shown.

Looking now why we have problem logging in as admin.

Here we have the following problem

NoMethodError: undefined method `pagestep' for #<Yus::EntitySession:0x0055a9f2a03088>
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/odba-1.1.2/lib/odba/drbwrapper.rb:28:in `method_missing'
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/2.4.0/drb/drb.rb:1624:in `perform_without_block'
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/2.4.0/drb/drb.rb:1584:in `perform'
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/2.4.0/drb/drb.rb:1668:in `block (2 levels) in main_loop'
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/2.4.0/drb/drb.rb:1664:in `loop'
        (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/2.4.0/drb/drb.rb:1664:in `block in main_loop'
        /home/niklaus/git/bbmb/lib/bbmb/html/state/customers.rb:54:in `page'
        /home/niklaus/git/bbmb/lib/bbmb/html/state/customers.rb:48:in `block in make_filter'
        /home/niklaus/git/sbsm/lib/sbsm/state.rb:239:in `view'
        /home/niklaus/git/sbsm/lib/sbsm/state.rb:173:in `to_html'
        /home/niklaus/git/sbsm/lib/sbsm/session.rb:484:in `to_html'
        /home/niklaus/git/sbsm/lib/sbsm/session.rb:243:in `block in process_rack'
        /home/niklaus/git/sbsm/lib/sbsm/session.rb:212:in `synchronize'
        /home/niklaus/git/sbsm/lib/sbsm/session.rb:212:in `process_rack'
        /home/niklaus/git/sbsm/lib/sbsm/app.rb:135:in `call'

This was easily fixed. Now I must find a way in bbmb/lib/bbmb/html/view/customers.rb @ line 107 BBMB::Html::View::CustomersList#valid to check the validity of the email. Eg. old code is @session.user.entity_valid?(model.email) which throws the following error

NoMethodError: undefined method `entity_valid?' for #<Yus::EntitySession:0x0055a9f2764480>
from (druby://127.0.0.1:12003) /usr/local/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/odba-1.1.2/lib/odba/drbwrapper.rb:28:in `method_missing'

This method is only defined in bbmb/lib/bbmb/html/util/known_user.rb.

Was able to start the old (non rack based) version of virbac by first installing all needed gems via /usr/local/bin/gem-240 and starting it in /var/www/virbac.bbmb.ch using sudo -u bbmb /usr/local/bin/ruby-240 /usr/local/bin/bbmbd -I/var/www/virbac.bbmb.ch/lib -rydim/invoice /usr/local/bin/bbmbd config=/var/www/virbac.bbmb.ch/etc/config.yml Debugging via pry in /usr/local/ruby-2.4.0/lib/ruby/gems/2.4.0/gems/bbmb-2.1.3/lib/bbmb/html/view/customers.rb shows

[1] pry(#<BBMB::Html::View::CustomersList>)> model.respond_to?(:valid) 
=> false
[2] pry(#<BBMB::Html::View::CustomersList>)> @session.user.entity_valid?(model.email)
Checking  for validity I am BBMB::Html::Util::KnownUser
D, [2017-05-08T15:07:10.300747 #12386] DEBUG -- User: admin@virbac.ch: allowed?(edit, yus.entities) -> true
=> false
[3] pry(#<BBMB::Html::View::CustomersList>)> @session.user
=> #<BBMB::Html::Util::KnownUser:0x007fea80db54f8 @auth_session=#<DRb::DRbObject:0x007fea80db5570 @ref=47367666624640, @uri="druby://127.0.0.1:12003">>
[4] pry(#<BBMB::Html::View::CustomersList>)> @session.user.class
=> BBMB::Html::Util::KnownUser

When I return always true in the method entity_valid? of lib/bbmb/html/util/known_user.rb, I am able to login as admin. Also going to http://virbac_rack.ngiger.ch/de/bbmb/customer/customer_id/708427 does not produce an error.

Must fix tomorrow the problem that the connection to the YUS is not maintained correctly. The sequences of states visited is like this for a normal user

session.rb:383:in `logout' logout "/de/bbmb/home/" setting @state 47177362502640 BBMB::Html::State::Login remember nil
session.rb:225:in `block in process_rack' active_state.trigger state 47177362502640 BBMB::Html::State::Login remember nil
session.rb:234:in `block in process_rack' Changing from 47177362502640 to state BBMB::Html::State::Login 47177362502640 remember nil
sbsm:state new view BBMB::Html::View::Login
login.rb:19:in `login' BBMB::Html::State Login login claude.meier@gmx.net xxxx  NilClass
viral_modules trying .Admin BBMB::Html::State::Viral::Admin
viral_modules trying .Customer BBMB::Html::State::Viral::Customer
Was allowed via user #<Yus::EntitySession:0x0056294a0aa220> for BBMB::Html::State::Viral::Customer
global.rb:26:in `initialize' BBMB::Html::State Global session BBMB::Html::Util::Session model BBMB::Html::Util::KnownUser
session.rb:225:in `block in process_rack' active_state.trigger state 70005995639600 BBMB::Html::State::CurrentOrder remember nil
session.rb:234:in `block in process_rack' Changing from 47177362502640 to state BBMB::Html::State::CurrentOrder 70005995639600 remember nil
sbsm:state new view BBMB::Html::View::CurrentOrder

For an admin use it is

session.rb:383:in `logout' logout "/de/bbmb/home/" setting @state 47396812145780 BBMB::Html::State::Login remember nil
session.rb:225:in `block in process_rack' active_state.trigger state 47396812145780 BBMB::Html::State::Login remember nil
session.rb:234:in `block in process_rack' Changing from 47396812145780 to state BBMB::Html::State::Login 47396812145780 remember nil
sbsm:state new view BBMB::Html::View::Login
session.rb:225:in `block in process_rack' active_state.trigger state 47396812145780 BBMB::Html::State::Login remember nil
session.rb:234:in `block in process_rack' Changing from 47396812145780 to state BBMB::Html::State::Login 47396812145780 remember nil
sbsm:state new view BBMB::Html::View::Login
login.rb:19:in `login' BBMB::Html::State Login login admin@virbac.ch 0874edc1ed285ee282a493b21d8bb9e3  NilClass
viral_modules trying .Admin BBMB::Html::State::Viral::Admin
Was allowed via user #<Yus::EntitySession:0x0056294a10f968> for BBMB::Html::State::Viral::Admin
viral_modules trying .Customer BBMB::Html::State::Viral::Customer
global.rb:26:in `initialize' BBMB::Html::State Global session BBMB::Html::Util::Session model BBMB::Html::Util::KnownUser
session.rb:225:in `block in process_rack' active_state.trigger state 69936301384740 BBMB::Html::State::Customers remember nil
customers.rb:19:in `init' State
session.rb:234:in `block in process_rack' Changing from 47396812145780 to state BBMB::Html::State::Customers 69936301384740 remember nil
sbsm:state new view BBMB::Html::View::Customers
view · edit · sidebar · attach · print · history
Page last modified on May 08, 2017, at 05:33 PM