class TestActHttpAuth

Public Instance Methods

test_all() click to toggle source
# File vendor/qwik/lib/qwik/act-httpauth.rb, line 81
    def test_all
      t_add_user

      # See the FrontPage.
      res = session '/test/'
      ok_title 'FrontPage'

      # See the FrontPage before Login.
      res = session('/test/') {|req|
        req.cookies.clear
      }
      ok_title 'Login'
      ok_xp [:meta, {:content=>"1; url=/test/.login", 'http-equiv'=>'Refresh'}],
            "//meta[2]"

      # See the Login page.
      res = session('/test/.login') {|req|
        req.cookies.clear
      }
      ok_title 'Login'
#      ok_xp [:a, {:href=>'.getpass'}, [:em, 'Get Password']],
#           "//div[@class='section']/a"
#      ok_xp [:a, {:href=>'.basicauth'}, 'Log in by Basic Authentication.'],
#           "//div[@class='section']/a[2]"

      # See the Basic Auth Login page.
      res = session('/test/.basicauth') {|req|
        req.cookies.clear
      }
      ok_title('Log in by Basic Authentication.')
      ok_eq(401, @res.status)
      ok_eq("Basic realm=\"qwik\"", @res['WWW-Authenticate'])

      # test base64
      ok_eq("dXNlckBlLmNvbTo5NTk4ODU5Mw==\n",
            Base64.encode64(DEFAULT_USER+':95988593'))

      # Try to Login by Basic Authenticate.
      res = session('/test/.basicauth') {|req|
        req.cookies.clear
        req.header['authorization'] =
          ["Basic dGVzdEBleGFtcGxlLmNvbTo0NDQ4NDEyNQ=="]
      }
      ok_title('Log in by Basic Authentication.')
      ok_eq(200, @res.status)
      ok_eq(nil, @res['WWW-Authenticate'])
      ok_xp([:a, {:href=>'FrontPage.html'}, 'Go back'], '//a')

      # Try to see FrontPage
      res = session('/test/') {|req|
        req.cookies.clear
        req.header['authorization'] =
          ["Basic dXNlckBlLmNvbTo5NTk4ODU5Mw=="]
      }
      ok_title('FrontPage')

      # test_logout
      res = session('/test/.logout') {|req|
        req.cookies.clear
        req.header['authorization'] =
          ["Basic dXNlckBlLmNvbTo5NTk4ODU5Mw=="]
      }
      ok_title('Basic Authentication Log out')
      assert_text('Can not log out.', 'h2')
    end