forked from brianolson/go-openid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyadis_test.go
77 lines (64 loc) · 2.85 KB
/
yadis_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2010 Florian Duraffourg. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Getting test data:
// curl -o test_data/py_id.html --dump-header test_data/py_id.http --header "Accept: application/xrds+xml" 'http://localhost:8000/id/bob'
// 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'
// curl -o test_data/orange_yadis.html --dump-header test_data/orange_yadis.http --header "Accept: application/xrds+xml" "http://www.orange.fr/"
// curl -o test_data/yahoo_yadis.html --dump-header test_data/yahoo_yadis.http --header "Accept: application/xrds+xml" "http://www.yahoo.com/"
// curl -o test_data/orange_xrds.html --dump-header test_data/orange_xrds.http --header "Accept: application/xrds+xml" "http://openid.orange.fr/xrds"
// 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"
// TODO: facebook? livejournal?
package openid
import (
"bytes"
"log"
"os"
"testing"
)
// searchHTMLMetaXRDS Test
type searchHTMLMetaXRDSTest struct {
in []byte
out string
}
var searchHTMLMetaXRDSTests = []searchHTMLMetaXRDSTest{
searchHTMLMetaXRDSTest{[]byte("<html><head><meta http-equiv='X-XRDS-Location' content='location'></meta></head></html>"), "location"},
searchHTMLMetaXRDSTest{[]byte("<html><head><meta http-equiv='X-XRDS-Location' content='location'></head></html>"), "location"},
searchHTMLMetaXRDSTest{[]byte("<html><head><meta http-equiv=\"x-xrds-location\" content=\"location\"></head></html>"), "location"},
//searchHTMLMetaXRDSTest{[]byte("<html><head><meta>location</meta></head></html>"), "location"},
}
func TestSearchHTMLMetaXRDS(t *testing.T) {
for _, l := range searchHTMLMetaXRDSTests {
content, err := searchHTMLMetaXRDS(bytes.NewBuffer(l.in))
if err != nil {
t.Errorf("searchHTMLMetaXRDS error: %s", err.Error())
}
if !bytes.Equal([]byte(content), []byte(l.out)) {
t.Errorf("searchHTMLMetaXRDS(%s) = %s want %s.", l.in, content, l.out)
}
}
}
// Yadis Test
type YadisTest struct {
url string
}
var YadisTests = []YadisTest{
YadisTest{"https://www.google.com/accounts/o8/id"},
YadisTest{"http://orange.fr/"},
//YadisTest{"http://www.yahoo.com/"},
}
// Test whether the Yadis function returns no errors and a non nil reader
// Doesn't test the content received
func TestYadis(t *testing.T) {
logger := log.New(os.Stdout, "TestYadis ", log.Ltime|log.Lmicroseconds|log.Lshortfile)
for _, yt := range YadisTests {
var reader, err = YadisVerbose(yt.url, logger)
if err != nil {
t.Errorf("Yadis(%s) returned a error: %s", yt.url, err.Error())
continue
}
if reader == nil {
t.Errorf("Yadis(%s) returned a nil reader", yt.url)
}
}
}