Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 78 lines (64 sloc) 2.919 kB
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
1 // Copyright 2010 Florian Duraffourg. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
9262c4e @brianolson return http.Client error testing tweak, think about more testing chan…
brianolson authored
5 // Getting test data:
824fab5 @brianolson add redir following to verify (but maybe we shouldn't) note fetching …
brianolson authored
6 // curl -o test_data/py_id.html --dump-header test_data/py_id.http --header "Accept: application/xrds+xml" 'http://localhost:8000/id/bob'
7 // curl -o test_data/google_yadis.html --dump-header test_data/google_yadis.http --header "Accept: application/xrds+xml" 'https://www.google.com/accounts/o8/id'
8 // curl -o test_data/orange_yadis.html --dump-header test_data/orange_yadis.http --header "Accept: application/xrds+xml" "http://www.orange.fr/"
9 // curl -o test_data/yahoo_yadis.html --dump-header test_data/yahoo_yadis.http --header "Accept: application/xrds+xml" "http://www.yahoo.com/"
7ed9da3 @brianolson fix VerifyValues postArgs construction
brianolson authored
10 // curl -o test_data/orange_xrds.html --dump-header test_data/orange_xrds.http --header "Accept: application/xrds+xml" "http://openid.orange.fr/xrds"
11 // curl -o test_data/yahoo_xrds.html --dump-header test_data/yahoo_xrds.http --header "Accept: application/xrds+xml" "http://open.login.yahooapis.com/openid20/www.yahoo.com/xrds"
9262c4e @brianolson return http.Client error testing tweak, think about more testing chan…
brianolson authored
12 // TODO: facebook? livejournal?
13
14
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
15 package openid
16
17 import (
18 "bytes"
824fab5 @brianolson add redir following to verify (but maybe we shouldn't) note fetching …
brianolson authored
19 "log"
20 "os"
21 "testing"
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
22 )
23
24 // searchHTMLMetaXRDS Test
25
26 type searchHTMLMetaXRDSTest struct {
dad73b4 @fduraffourg Details
fduraffourg authored
27 in []byte
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
28 out string
29 }
30
dad73b4 @fduraffourg Details
fduraffourg authored
31 var searchHTMLMetaXRDSTests = []searchHTMLMetaXRDSTest{
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
32 searchHTMLMetaXRDSTest{[]byte("<html><head><meta http-equiv='X-XRDS-Location' content='location'></meta></head></html>"), "location"},
9262c4e @brianolson return http.Client error testing tweak, think about more testing chan…
brianolson authored
33 searchHTMLMetaXRDSTest{[]byte("<html><head><meta http-equiv='X-XRDS-Location' content='location'></head></html>"), "location"},
34 searchHTMLMetaXRDSTest{[]byte("<html><head><meta http-equiv=\"x-xrds-location\" content=\"location\"></head></html>"), "location"},
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
35 //searchHTMLMetaXRDSTest{[]byte("<html><head><meta>location</meta></head></html>"), "location"},
36 }
37
38 func TestSearchHTMLMetaXRDS(t *testing.T) {
39 for _, l := range searchHTMLMetaXRDSTests {
40 content, err := searchHTMLMetaXRDS(bytes.NewBuffer(l.in))
41 if err != nil {
51525ef @paddyforan Update tests to use new error package format.
paddyforan authored
42 t.Errorf("searchHTMLMetaXRDS error: %s", err.Error())
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
43 }
dad73b4 @fduraffourg Details
fduraffourg authored
44 if !bytes.Equal([]byte(content), []byte(l.out)) {
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
45 t.Errorf("searchHTMLMetaXRDS(%s) = %s want %s.", l.in, content, l.out)
46 }
47 }
48 }
49
50 // Yadis Test
51
52 type YadisTest struct {
53 url string
54 }
55
dad73b4 @fduraffourg Details
fduraffourg authored
56 var YadisTests = []YadisTest{
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
57 YadisTest{"https://www.google.com/accounts/o8/id"},
58 YadisTest{"http://orange.fr/"},
00f5d32 @paddyforan Updated tests to use new error syntax.
paddyforan authored
59 //YadisTest{"http://www.yahoo.com/"},
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
60 }
61
62 // Test whether the Yadis function returns no errors and a non nil reader
63 // Doesn't test the content received
64 func TestYadis(t *testing.T) {
824fab5 @brianolson add redir following to verify (but maybe we shouldn't) note fetching …
brianolson authored
65 logger := log.New(os.Stdout, "TestYadis ", log.Ltime|log.Lmicroseconds|log.Lshortfile)
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
66 for _, yt := range YadisTests {
824fab5 @brianolson add redir following to verify (but maybe we shouldn't) note fetching …
brianolson authored
67 var reader, err = YadisVerbose(yt.url, logger)
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
68 if err != nil {
51525ef @paddyforan Update tests to use new error package format.
paddyforan authored
69 t.Errorf("Yadis(%s) returned a error: %s", yt.url, err.Error())
231e73a @fduraffourg Rewrite of the authentication request part
fduraffourg authored
70 continue
71 }
72 if reader == nil {
73 t.Errorf("Yadis(%s) returned a nil reader", yt.url)
74 }
75 }
dad73b4 @fduraffourg Details
fduraffourg authored
76 }
9262c4e @brianolson return http.Client error testing tweak, think about more testing chan…
brianolson authored
77
Something went wrong with that request. Please try again.