3 class ClientApplicationsTest < ActionDispatch::IntegrationTest
5 # run through the procedure of creating a client application and checking
6 # that it shows up on the user's account page.
7 def test_create_application
11 assert_redirected_to login_path(:cookie_test => "true")
13 assert_response :success
14 post "/login", :params => { "username" => user.email, "password" => "test", :referer => "/user/#{ERB::Util.u(user.display_name)}" }
15 assert_response :redirect
17 assert_response :success
18 assert_template "users/show"
20 assert_response :success
21 assert_template "accounts/edit"
23 # check that the form to allow new client application creations exists
25 assert_select "ul.nav.nav-tabs li.nav-item a[href='/user/#{ERB::Util.u(user.display_name)}/oauth_clients']"
28 # now we follow the link to the oauth client list
29 get "/user/#{ERB::Util.u(user.display_name)}/oauth_clients"
30 assert_response :success
32 assert_select "a[href='/user/#{ERB::Util.u(user.display_name)}/oauth_clients/new']"
35 # now we follow the link to the new oauth client page
36 get "/user/#{ERB::Util.u(user.display_name)}/oauth_clients/new"
37 assert_response :success
39 assert_select "h1", "Register a new application"
42 assert_select "form[action='/user/#{ERB::Util.u(user.display_name)}/oauth_clients']" do
43 [:name, :url, :callback_url, :support_url].each do |inp|
44 assert_select "input[name=?]", "client_application[#{inp}]"
46 ClientApplication.all_permissions.each do |perm|
47 assert_select "input[name=?]", "client_application[#{perm}]"
52 post "/user/#{ERB::Util.u(user.display_name)}/oauth_clients",
53 :params => { "client_application[name]" => "My New App",
54 "client_application[url]" => "http://my.new.app.org/",
55 "client_application[callback_url]" => "http://my.new.app.org/callback",
56 "client_application[support_url]" => "http://my.new.app.org/support" }
57 assert_response :redirect
59 assert_response :success
60 assert_template "oauth_clients/show"
61 assert_equal "Registered the information successfully", flash[:notice]
63 # now go back to the account page and check its listed under this user
64 get "/user/#{ERB::Util.u(user.display_name)}/oauth_clients"
65 assert_response :success
66 assert_template "oauth_clients/index"
67 assert_in_body { assert_select "li>a", "My New App" }
71 # fake client workflow.
72 # this acts like a 3rd party client trying to access the site.
73 def test_3rd_party_token
74 # apparently the oauth gem doesn't really support being used inside integration
75 # tests, as its too tied into the HTTP headers and stuff that it signs.
81 # utility method to make the HTML screening easier to read.
82 def assert_in_heading(&block)
83 assert_select("div.content-heading", &block)
87 # utility method to make the HTML screening easier to read.
88 def assert_in_body(&block)
89 assert_select("div#content", &block)