Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
clean code (#23)
Browse files Browse the repository at this point in the history
* clean code

* check for presence of state
  • Loading branch information
ishangulhane authored Jul 16, 2019
1 parent 2ce9dad commit b42955d
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions tests/framework/appid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package framework
import (
"encoding/json"
"fmt"
"github.com/PuerkitoBio/goquery"
"github.com/ibm-cloud-security/app-identity-and-access-adapter/adapter/authserver"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
"testing"

"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

"github.com/ibm-cloud-security/app-identity-and-access-adapter/adapter/authserver"
)

const (
Expand All @@ -33,7 +35,7 @@ const (
contentType = "Content-Type"
setCookie = "set-cookie"
widgetURLID = "#widgetUrl"
stateID = "#cd_form .form-group"
stateID = "#cd_form input[name='state']"
)

// AppIDManager models the authorization server
Expand Down Expand Up @@ -171,16 +173,8 @@ func (m *AppIDManager) initialRequestToFrontend(t *testing.T, path string) (adap

// Parse login page
doc, err := goquery.NewDocumentFromReader(redirectRes.Body)
var state string
doc.Find(stateID).Each(func(i int, s *goquery.Selection) {
_ = s.Find("input").Each(func(i int, q *goquery.Selection) {
name, _ := q.Attr("name")
value,_ := q.Attr("value")
if name == "state" {
state = value
}
})
})
state, statePresent := doc.Find(stateID).Attr("value")
require.True(t, statePresent)
widgetUrl, okW := doc.Find(widgetURLID).Attr("value")
require.True(t, okW)
return stateCookie, state, widgetUrl
Expand Down

0 comments on commit b42955d

Please sign in to comment.