Foreign key on table nonce is invalid for new nonce
Foreign key on table nonce is invalid for new nonce
| Issue ID: | 1251 |
| Issue Category: | bug |
| Component: | core |
| Priority: | major |
| Status: | fixed |
| Assigned: | evan |
| Version: | 0.7 |
| Milestone: | 0.7 |
| Keywords: | database, omb |
nonce has the foreign key
{{{
constraint foreign key (consumer_key, tok) references token (consumer_key, tok)
}}}
yet when created a nonce gets no tok:
{{{
INSERT INTO nonce (consumer_key , nonce , created ) VALUES ('http://virtual/laconica/' , '7927c83094066e6012b949906c9756f0' , '2009-02-21 19:57:45')
}}}
That leads to the mysql error
{{{
Cannot add or update a child row: a foreign key constraint fails (`laconica2/nonce`, CONSTRAINT `nonce_ibfk_1` FOREIGN KEY (`consumer_key`, `tok`) REFERENCES `token` (`consumer_key`, `tok`))
}}}

Updates
#1
Steps to reproduce:
Two clean laconica installations (0.7.x branch): http://virtual/laconica and http://virtual2/laconica2. A user http://virtual/laconica/adrianlang tries to subscribe to http://virtual2/laconica2/adr2nd.
virtual2/laconica2 fails to get a request token from virtual/laconica; the method Remotesubscription::requestToken returns null. $req in this method is
{{{
OAuthRequest Object
(
[parameters:private] => Array
(
[oauth_version] => 1.0
[oauth_nonce] => 292a48485e89d676718f7c6a07552e4b
[oauth_timestamp] => 1235330217
[oauth_consumer_key] => http://virtual2/laconica2/
[action] => requesttoken
[omb_listener] => http://virtual/laconica/adrianlang
[omb_version] => http://openmicroblogging.org/protocol/0.1
[oauth_signature_method] => HMAC-SHA1
[oauth_signature] => tW+elRhGjQwdyyw/ZXq8ZOsNQNM=
)
[http_method:private] => POST
[http_url:private] => http://virtual/laconica/index.php?action=requesttoken
[base_string] => POST&http%3A%2F%2Fvirtual%2Flaconica%2Findex.php&action%3Drequesttoken%26oauth_consumer_key%3Dhttp%253A%252F%252Fvirtual2%252Flaconica2%252F%26oauth_nonce%3D292a48485e89d676718f7c6a07552e4b%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1235330217%26oauth_version%3D1.0%26omb_listener%3Dhttp%253A%252F%252Fvirtual%252Flaconica%252Fadrianlang%26omb_version%3Dhttp%253A%252F%252Fopenmicroblogging.org%252Fprotocol%252F0.1
)
}}}
The $result looks like:
{{{
Auth_Yadis_HTTPResponse Object
(
[final_url] => http://virtual/laconica/index.php
[status] => 500
[headers] => Array
(
[Date] => Sun, 22 Feb 2009 19:16:57 GMT
[Server] => Apache/2.2.9 (Debian) Phusion_Passenger/2.0.6 PHP/5.2.6-1+lenny2 with Suhosin-Patch
[X-Powered-By] => PHP/5.2.6-1+lenny2
[Vary] => Accept-Encoding
[Connection] => close
[Transfer-Encoding] => chunked
[Content-Type] => text/html; charset=utf-8
)
[body] =>
[html stuff]
Database error
The database for 1st isn't responding correctly, so the site won't work properly. The site admins probably know about the problem, but you can contact them at webmaster@localhost to make sure. Otherwise, wait a few minutes and try again.
[more html stuff]
)
}}}
The problem can be tracked down to the sql statement mentioned above. The problematic call is {{{$this->check_nonce($consumer, $token, $nonce, $timestamp);}}} in OAuthServer::check_signature in extlib/OAuth.php. In this call, $consumer is
{{{
OAuthConsumer Object
(
[key] => http://virtual2/laconica2/
[secret] =>
[callback_url] =>
)
}}}
$token is empty, $nonce is a valid nonce and $timestamp the correct timestamp.
So the problem is the empty $token. check_signature is called from fetch_request_token, and there are the three lines
{{{
// no token required for the initial token request
$token = NULL;
$this->check_signature($request, $consumer, $token);
}}}
#2
Evan fixed it by correcting the constraints.
You can also subscribe to the
RSS feed for updates to this issue.