func TestBewit(t *testing.T) {
	url := fmt.Sprintf("https://auth.taskcluster.net/v1/client/%s/scopes", CLIENT_ID)

	bewitUrl, err := tc.Bewit(CLIENT_ID, ACCESS_TOKEN, url)
	if err != nil {
		t.Errorf("Failed to create bewit %v", err)
	}

	httpClient := &http.Client{}
	req, err := http.NewRequest("GET", bewitUrl, nil)
	if err != nil {
		t.Errorf("Failed to create request: %s", err)
	}
	resp, err := httpClient.Do(req)
	if err != nil {
		t.Errorf("Error issuing request", err)
	}

	// Ensure the body is closed after this test.
	defer resp.Body.Close()
	json, err := readJson(resp)

	if err != nil {
		t.Errorf("Failed to decode json of getScopes %s", err)
	}

	if json.ClientId != CLIENT_ID {
		t.Errorf("Client is does not match")
	}
}
Esempio n. 2
0
func (self Routes) signUrl(res http.ResponseWriter, req *http.Request) {
	// Using ReadAll could be sketchy here since we are reading unbounded data
	// into memory...
	body, err := ioutil.ReadAll(req.Body)

	if err != nil {
		res.WriteHeader(500)
		fmt.Fprintf(res, "Error reading body")
		return
	}

	urlString := strings.TrimSpace(string(body))
	bewitUrl, err := tc.Bewit(self.ClientId, self.AccessToken, urlString)

	if err != nil {
		res.WriteHeader(500)
		fmt.Fprintf(res, "Error creating bewit url")
		return
	}

	headers := res.Header()
	headers.Set("Location", bewitUrl)
	res.WriteHeader(303)
	fmt.Fprintf(res, bewitUrl)
}